0

我正在尝试使用 Java 类将 JSON 对象发送到 Struts2 Action,但 Struts 没有填充该类。我正在使用 JSON 拦截器来执行此操作。

我没有收到任何错误,但类中的属性保持为空。

我的 Struts 库是:

struts2-core-2.3.24.1 struts2-json-plugin-2.3.24.1 json-lib-2.3-jdk15

感谢帮助!

我的 struts.xml

<package name="default" namespace="/" extends="json-default">


<interceptors>
            <interceptor-stack name="jsonDefaultStack">
                <interceptor-ref name="json">
                    <param name="enableSMD">true</param>
                    <param name="excludeNullProperties">true</param>
                    <param name="includeProperties">jsonCustomer</param>
                     <param name="ignoreSMDMethodInterfaces">false</param>
                </interceptor-ref>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="jsonDefaultStack" />


        <action name="angularAction" class="actions.CustomerAction" method="findCustomer" >

            <result type="json">
                  <param name="root">jsonCustomer</param>
                  <param name="excludeNullProperties">true</param>
                  <param name="noCache">true</param>

            </result>


        </action>

    </package>

我的 Struts 动作

public class CustomerAction extends ActionSupport  {

    private List<Customer> jsonCustomer;    


    public List<Customer> getJsonCustomer() {
        return jsonCustomer;
    }


    public void setJsonCustomer(List<Customer> jsonCustomer) {
        this.jsonCustomer = jsonCustomer;
    }


    public String findCustomer() {      

        List<Customer> js = getJsonCustomer();      

        return SUCCESS;

    }
}

我的 Java 类

public class Customer {

    private String id;
    private String name;
    private String email;
    private String phone;

    public Customer() {

    }

    public Customer(String id, String name, String email, String phone) {

        this.id = id;
        this.name = name;
        this.email = email;
        this.phone = phone;

    }

//GETTERS AND SETTERS
}

我的 AngularJS 控制器

angular.module('myApp', []);

    angular.module('myApp').
    controller('MyController',  function ($scope, $http) {
        $scope.getDataFromServer = function(customer) {

             var vjson = {"customer": [{ "id":"4" , "name":"John" , "email":"Doe", "phone":"44444"  }]}; 

                $http({
                    url: 'angularAction',
                    method: 'POST',
                    data: angular.toJson(vjson),
                    headers:{'Content-Type':'application/json'}
                }).then (function successCallback(response) {

                }, function errorCallback(response) {

                })      

            };
        });
4

0 回答 0