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]
 

原因
SpringBoot 2.x默认不支持==put,delete等请求方式的。
解决方法
- 在配置文件
application.properties中启用hiddenMethod过滤器 
# 启用hiddenMethod过滤器
spring.mvc.hiddenmethod.filter.enabled=true
 
- 然后在
form标签里面声明method为post。 
<form th:action="@{/emp/}+${emp.id}" method="post">
 
- 最后在
form里面使用以下标签。 
<input th:type="hidden" name="_method" value="put">
 
name必须为"_method",value值就是你想使用的请求方式,put或者delete等。
                    
                
                
            
        
浙公网安备 33010602011771号