java - postman 的 Springboot @PutMapping 405 错误

标签 java spring-boot

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/

相关文章:

java - 如何避免 Spring ConversionService 中的重复转换器?

java - 如何递归获取图形中可以包含循环的所有连接节点?

java - 如果使用相同的负载发出另一个请求,应使用哪种 RequestBody 类型?

json - 如何测试 Spring Boot Controller 的错误输出?

regex - Spring-Boot @RequestMapping 和@PathVariable 正则表达式匹配

spring - 更新pom.xml中的Spring-boot版本时出现错误?

Java功能流: generate a set of random points between distance A and B from each other

java - 类有两个同名属性 "actionsList"

java - 使用 OWB 在 TomEE 上部署 Wicket CDI

java - Spring Boot中如何防止MultipartFile自动保存到本地目录?