gpt4 book ai didi

java - postman 的 Springboot @PutMapping 405 错误

转载 作者:行者123 更新时间:2023-12-02 00:26:56 26 4
gpt4 key购买 nike

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/

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