首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >弹簧休息误差500

弹簧休息误差500
EN

Stack Overflow用户
提问于 2017-04-30 09:02:33
回答 1查看 1.9K关注 0票数 1

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

我的控制器功能如下所示:

代码语言:javascript
运行
复制
@RequestMapping(value="sites", method=RequestMethod.DELETE)
boolean deleteSite(@PathVariable("siteId") int site_id, HttpServletResponse res){
    .......
}

AngularJS函数是:

代码语言:javascript
运行
复制
$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);
            }
        }

与工厂:

代码语言:javascript
运行
复制
serverApp.factory('referentFactory',['$resource',function ($resource){
   return $resource("http://localhost:8080/Guard_Server/restapi/referents",null,{ 'update': {method: 'PUT'} });
}]);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-30 09:33:28

就像我在网址上看到的

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

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

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

@RequestParam

代码语言:javascript
运行
复制
   http://localhost:8080/Guard_Server/restapi/sites?siteId=5

@PathVariable

代码语言:javascript
运行
复制
   http://localhost:8080/Guard_Server/restapi/sites/siteId/5

see this for more information

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43704696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档