gpt4 book ai didi

javascript - Spring REST 错误 500

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:42 25 4
gpt4 key购买 nike

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

我的 Controller 功能如下:

@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'} });
}]);

最佳答案

正如我在网址中看到的

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

您应该使用@RequestParam而不是@PathVariable

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

@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

关于javascript - Spring REST 错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43704696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com