Springboot版本2.1.8.RELEASE
controller
@PutMapping("/sample/{id}")
public Sample update(@PathVariable String id, @RequestBody Sample s){
s.setId(id);
return sampleService.update(s);
}
postman
放置http://localhost:8080/sample/sspa01
返回
{
"status": 405,
"error": "Method Not Allowed",
"message": "Request method 'PUT' not supported",
"path": "/sample/sspa01"
}
感谢您让我知道如何解决此问题
最佳答案
这里可以通过在现有的方法映射中定义 PUT 的显式映射来解决这个问题
试试这个
//@PutMapping("/sample/{id}")
@RequestMapping(value = "/sample/{id}", produces = "application/json", method=RequestMethod.PUT)
@RequestMapping(value = "/sample/{id}", produces = "application/json", method=RequestMethod.PUT)
public Sample update(@PathVariable("id") String id, @RequestBody Sample s){
s.setId(id);
return sampleService.update(s);
}
关于java - postman 的 Springboot @PutMapping 405 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58046931/