【解决方法】SpringBoot删除表单报错:Request method ‘POST’ not supported

  • Post author:
  • Post category:其他




现象

按照

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


默认不支持

==

put



delete

等请求方式的。



解决方法

  1. 在配置文件

    application.properties

    中启用

    hiddenMethod

    过滤器
# 启用hiddenMethod过滤器
spring.mvc.hiddenmethod.filter.enabled=true
  1. 然后在

    form

    标签里面声明

    method



    post

<form th:action="@{/emp/}+${emp.id}" method="post">
  1. 最后在

    form

    里面使用以下标签。
<input th:type="hidden" name="_method" value="put">


name

必须为”

_method

“,

value

值就是你想使用的请求方式,

put

或者

delete

等。



版权声明:本文为ageovb原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。