使用ngResource从spring mvc到angular js的响应不正确

Response not coming properly from spring mvc to angular js using ngResource

本文关键字:js 响应 不正确 angular ngResource spring mvc 使用      更新时间:2023-09-26

我使用spring mvc和angular js在各自的后端和前端的应用程序。我使用ngresource的http调用。但是作为响应,我不能正确地得到响应。

. 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();
});

我从我的spring MVC传递对象。但是,我没有得到响应。

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

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

或多个:

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