DELETE上的$ resource不会在json中序列化数据

时间:2015-06-23 16:37:36

标签: angularjs

在POST方法中使用$ resource时(我要在服务器上删除的项目类型为#34; Todo") 我的java SpringREST后台控制器看起来像:

/**
 * POST : delete an todo : /todos/DEL
 */
@RequestMapping(value = "/DEL", method = RequestMethod.POST)
public void deletePOST(@RequestBody Todo todo) {
    todoRepository.delete(todo);
}

角度代码:

 vm.deleteTodoRes2 = function deleteTodoRes2(todo) {
                console.log(todo);
                var url = REST_SERVER_URL + "/todos/DEL";
                var urlParamDefaults = {};
                var action = {
                    removeResource: {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        isArray: false,
                        transformRequest : function(data, headers) {
                            console.log("data");
                            console.log(data);
                            var out = angular.toJson(data);
                            console.log("out ");
                            console.log(out);
                            return  out;
                        }
                    }
                };
                var rest = $resource(url, urlParamDefaults, action);
                // API : rest.<method> ( [param],
                //                       if NON GET [entityData],
                //                      [success(value, responseHeaders)], [error(httpResponse)] )
                var param = {};
                rest.removeResource(param, todo,  successCallback, errorCallback);
            };

它与POST完美结合, 现在,如果我尝试将http方法从POST更改为DELETE,它将不再起作用。

春天:

 @RequestMapping(value = "/DEL", method = RequestMethod.DELETE)  <<< only change in JAVA
In JS

var action = {  removeResource: { method: 'DELETE ', <<< only change in JS

它不起作用, console.log(数据); =&GT;未定义 似乎Angular不想采取我的&#34; toto&#34;数据并在json中序列化, 为什么?

0 个答案:

没有答案