使用ngResource从弹簧mvc到角度js的响应不正确

时间:2015-06-08 10:39:21

标签: javascript angularjs spring spring-mvc

我正在使用spring mvc和angular js在各自的后端和前端中应用。我正在使用ngresource进行http调用。但作为回应,我无法正确得到答案。

test.js

angular.module('app').factory("testService",

    function($resource) {
        return {
            getdata: $resource('/setupdata',{},
              {
                'save' : {
                method:'POST'
            }
            })  };
    });
    angular.module('app').controller('testController',function($scope, $http,testService) {
    var init = function(){
    testService.getdata.get(function(response) {
    //in response age,height etc is there
    //if I put alert I am getting[Object,Object] and If I put JSON.stringify(data) all the parameters are appearing like age , height etc,If I check with data.age, data.height a blank braces is coming {}.
    } 
    init();
});

我从我的春季MVC传递Object。但是,我没有得到回复。

1 个答案:

答案 0 :(得分:0)

$resource.get()期望查询参数对象为第一个参数:

testService.getdata.get({ id: 12 }, function(response) {
    console.log(response);
});

或多个:

testService.getdata.query({}, function(response) {
    console.log(response);
});