我正在使用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'} });
}]);
答案 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