簡體   English   中英

來自 postman 的 Springboot @PutMapping 405 錯誤

[英]Springboot @PutMapping 405 error from postman

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);
    }

在我的情況下,url 不是 permitAll() 的一部分,一旦添加它就可以正常工作,您能否檢查您的 @EnableWebSecurity 配置以了解以下方法

@Bean SecurityFilterChain filterChain(HttpSecurity http)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM