简体   繁体   English

Spring REST错误500

[英]Spring REST error 500

I am implementing REST service using Spring. 我正在使用Spring实现REST服务。 When i call delete function the request doesn't reach controller and from JS i receive error: angular.js:12587 DELETE http://localhost:8080/Guard_Server/restapi/sites?siteId=5 500 (Internal Server Error) 当我调用delete函数时,请求没有到达控制器,并且从JS收到错误:angular.js:12587 DELETE http:// localhost:8080 / Guard_Server / restapi / sites?siteId = 5 500(内部服务器错误)

my controller function looks like: 我的控制器功能如下:

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

And AngularJS function is: 而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);
            }
        }

with factory: 与工厂:

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

As I see in the url 正如我在网址中看到的那样

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

you should use @RequestParam instead of @PathVariable . 你应该使用@RequestParam而不是@PathVariable

@RequestParam use for access query parameter and @PathVariable is part of url. @RequestParam用于访问查询参数, @PathVariable是url的一部分。

@RequestParam : @RequestParam

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

@PathVariable @PathVariable

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

see this for more information 有关更多信息,请参阅此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MVC,AngularJS错误500 - Spring MVC ,AngularJS error 500 在邮递员 500 中创建 REST API 时出错 - Error while creating rest API in postman 500 创建列表项 Sharepoint REST API Javascript 返回错误 500 - Creating List Item Sharepoint REST API Javascript returns Error 500 错误415.使用Spring的Service REST-AngularJs - Error 415. Service REST with Spring - AngularJs 为什么从 api 接收到的图像给出 500 错误但正确接收数据的 rest? - Why the received images from api give 500 error but receive the rest of the data correctly? 猫鼬自定义类型在hapi / rest-hapi中导致500个内部服务器错误 - Mongoose custom type causes 500 internal server error in hapi / rest-hapi 在 Rest API 调用上使用 @Consumes 注释给出 500 Internal Server Error - Using @Consumes annotation on Rest API call giving 500 Internal Server Error 尝试创建付款对象时,PayPal REST API返回500-错误 - PayPal REST API returning 500-Error when trying to create payment-object 在Spring Boot应用程序中从Angular JS调用Rest Services时出错 - Error in calling Rest Services from Angular JS in a Spring Boot application 使用 get 方法从 angularjs 调用 spring 引导 web 服务,不起作用是给出 500 状态错误 - Calling spring boot webservice from angularjs with get method, is not working is giving 500 status error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM