Spring REST错误500

时间:2017-04-30 09:02:34

标签: javascript java angularjs spring rest

我正在使用Spring实现REST服务。当我调用delete函数时,请求没有到达控制器,并且从JS收到错误:angular.js:12587 DELETE http://localhost:8080/Guard_Server/restapi/sites?siteId=5 500(内部服务器错误)

我的控制器功能如下:

@RequestMapping(value="sites", method=RequestMethod.DELETE)
boolean deleteSite(@PathVariable("siteId") int site_id, HttpServletResponse res){
    .......
}

AngularJS功能是:

$scope.deleteSite=function(){
            if(confirm("Are you sure you want to delete this Site?")){
                var site={};
                site.siteId=sites[$scope.selectedSite].id;
                console.log(site);
                siteFactory.delete(site).$promise.then(function(result){
                    ...
                }
                ,error_on_execute);
            }
        }

与工厂:

serverApp.factory('referentFactory',['$resource',function ($resource){
   return $resource("http://localhost:8080/Guard_Server/restapi/referents",null,{ 'update': {method: 'PUT'} });
}]);

1 个答案:

答案 0 :(得分:0)

正如我在网址中看到的那样

<强> http://localhost:8080/Guard_Server/restapi/sites?siteId=5

您应该使用@RequestParam代替@PathVariable

@RequestParam用于访问查询参数,@PathVariable是网址的一部分。

@RequestParam

   http://localhost:8080/Guard_Server/restapi/sites?siteId=5

<强> @PathVariable

   http://localhost:8080/Guard_Server/restapi/sites/siteId/5

see this for more information