按照尚硅谷的Spring教程写表单删除
报错如下:

2020-04-21 08:32:59.502  WARN 8972 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : 
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

SpringBoot 删除表单报错:Request method 'POST' not supported

原因

SpringBoot 2.x默认不支持==putdelete等请求方式的。

解决方法

  1. 在配置文件application.properties中启用hiddenMethod过滤器
# 启用hiddenMethod过滤器
spring.mvc.hiddenmethod.filter.enabled=true
  1. 然后在form标签里面声明methodpost
<form th:action="@{/emp/}+${emp.id}" method="post">
  1. 最后在form里面使用以下标签。
<input th:type="hidden" name="_method" value="put">

name必须为"_method",value值就是你想使用的请求方式,put或者delete等。

相关文章:

  • 2021-07-11
  • 2022-12-23
  • 2021-09-28
  • 2021-10-22
  • 2021-09-25
  • 2021-08-21
  • 2021-08-19
猜你喜欢
  • 2021-10-03
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
相关资源
相似解决方案