Struts2 Json-plugin没有填充我的类

时间:2015-10-28 15:15:22

标签: java json angularjs struts2 struts2-json-plugin

我试图用Java类向Struts2 Action发送一个JSON对象,但Struts没有填充该类。我正在使用JSON Interceptor来执行此操作。

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

My Struts库是:

struts2的核 - 2.3.24.1 struts2的-JSON-插件-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>

My Struts Action

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) {

                })      

            };
        });

0 个答案:

没有答案