Spring boot: Request method 'PUT' not supported

前端 未结 5 1628
傲寒
傲寒 2021-01-07 06:12

I am getting a Request method \'PUT\' not supported error on hitting a PUT method on a restful API to upload a file.

Following is the

5条回答
  •  星月不相逢
    2021-01-07 06:39

    Chek you request mapping

    if you declare request mapping in class level @RequestMapping("/api/users") then if you declare mapping in method level @RequestMapping("/api/users/{id}") this error could occur.

    correct

    @RequestMapping("/api/users")
     public class {.....
    
       @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
       update(....)
    
    } 
    

    incorrect , might cause PUT not supported error

    @RequestMapping("/api/users")
     public class {.....
    
       @RequestMapping(value = "/api/users/{id}", method = RequestMethod.PUT)
       update(....)
    
    } 
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题