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

现象

按照尚硅谷的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]

HttpRequestMethodNotSupportedException

原因

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等。

posted @ 2020-04-21 10:40  ageovb  阅读(402)  评论(0编辑  收藏  举报