.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported]
时间: 2023-11-02 11:02:07 浏览: 48
这个错误信息是由于在实现Restful风格的删除操作时,使用了delete方式提交,但实际上还是以post方式进行了提交,导致了请求方法不支持的错误。造成这个问题的原因可能是在HTML代码中没有正确配置delete请求的方式。
要解决这个问题,你可以尝试以下步骤:
1. 在UserController中添加一个处理delete请求的方法,使用@DeleteMapping注解来标识该方法处理delete请求。
2. 在HTML代码中,将form的method属性设置为"post",然后添加一个隐藏的input元素,name属性设置为"_method",value属性设置为"delete"。这样可以模拟发送delete请求。
3. 在Spring Boot项目中添加spring-boot-starter-thymeleaf依赖,确保Thymeleaf模板引擎能够正确解析HTML代码。
相关问题
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
当你看到org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported的错误消息时,它意味着你正在尝试使用PUT请求方法,但该方法在你的代码中并未被支持。
这通常是因为你的代码中没有相应的处理程序方法来处理PUT请求。在你的代码中,你使用了@PostMapping注释来映射HTTP POST请求到特定的处理程序方法。但是,你需要使用@RequestMapping注释来映射HTTP PUT请求到相应的处理程序方法,或者使用@PutMapping注释作为快捷方式来映射HTTP PUT请求。
简而言之,你需要在你的代码中添加一个处理程序方法,并使用@RequestMapping或@PutMapping注释将该方法映射到HTTP PUT请求。这样,当你使用PUT请求时,就不会再出现org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported的错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET‘ not supported](https://blog.csdn.net/weixin_45157411/article/details/123665632)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET‘ not...](https://blog.csdn.net/qq_44347175/article/details/125697957)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
怎么解决Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported]
根据您提供的引用内容,出现"org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported"错误是因为请求方法不支持PUT方法。解决这个问题的方法是将请求方法改为支持PUT方法的方式。
您可以使用@RequestMapping注解来指定请求方法,将value属性设置为"/update_start",并将method属性设置为RequestMethod.PUT。修改后的代码如下所示:
```java
@ResponseBody
@RequestMapping(value = "/update_start", method = RequestMethod.PUT)
public void update_start(){
System.out.println("1111111");
}
```
请注意,您还可以根据需要使用其他的注解,如@PutMapping,来简化代码。这将确保您的方法支持PUT请求,并解决"org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported"错误。