[英]405 Method not allowed in Spring Boot and Ajax
Hi I am having request mapping like this嗨,我有这样的请求映射
@RequestMapping(value = "/pendodnp/{visitorId}/{content}")
public ResponseEntity<Object> setPendoDNP(@PathVariable String visitorId, @PathVariable String content, final HttpSession session, final HttpServletRequest request) throws PendoException {
LOGGER.info("### pendodnp");
_splitService.updateDNP(visitorId, content);
return ResponseEntity.ok().body(content);
}
but when I hit this URL from an angular function, it gives "405 method not allowed" error.但是当我从 angular function 中点击这个 URL 时,它给出了“不允许 405 方法”错误。
$http.get("pendodnp/"+visitorId+"/"+dnpValue, JSON.stringify(dnpValue))
.success(function(response) {
Here is screenshot of how the request is going, can someone tell me what i am missing here?这是请求进行情况的屏幕截图,有人可以告诉我我在这里缺少什么吗?
You haven't specified which HTTP method (GET, POST, PUT, DELETE, etc) the mapping should handle.您尚未指定映射应处理的 HTTP 方法(GET、POST、PUT、DELETE 等)。 To do that either use
@GetMapping
or change your @RequestMapping
so it includes the method
parameter.为此,请使用
@GetMapping
或更改您的@RequestMapping
以使其包含method
参数。
@GetMapping("/pendodnp/{visitorId}/{content}")
Or或者
import static org.springframework.web.bind.annotation.RequestMethod.GET;
...
@RequestMapping(method = GET, path = "/pendodnp/{visitorId}/{content}")
Using @RequestMapping
without a method
parameter is usually only done at the class level, not individual methods.在没有
method
参数的情况下使用@RequestMapping
通常只在class级别完成,而不是单个方法。 @GetMapping
(or @PostMapping
, @PutMapping
, etc) are more common on controller methods . @GetMapping
(或@PostMapping
、 @PutMapping
等)在 controller方法上更常见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.