百里叶 - th:method =" delete/put&quot导致:请求方法' post'不支持
我使用从“ start.spring.io”安装的Spring Boot v2.7.0,然后从那里安装了胸腺,当我在父pom中搜索时,我发现: 胸腺pring5(v3.0.15.Release),胸腺extras-java8time(v3.0.4.4.Release)
,我需要应用模式< form th th:method th:method th:put/delete'.../delete“ ...//delete” .../ > 。 在Verious的地方进行了谷歌搜索后,我找到了该解决方案,该解决方案也在书中也被重新提到: “ 驯服胸腺的实用指南,构建具有弹簧靴和百里角的网络应用程序-Wim Deblauwe ” 这是胸腺的顶级/优秀书籍,我从中学到了百里香。 对这些的态度,我做到了:
步骤1:
在 application.properties 中添加了此属性:
spring.mvc.hiddenmethod.filter.enabled=true
我在 application.yaml 中尝试了它第二个解决方案,因为以前没有工作),就像这样:
spring:
mvc:
hiddenmethod:
filter:
enabled: true
步骤2:
我使用了:
<form th:method="put".../>
<form th:method="delete".../>
步骤3:
最后我使用了:“ @put> @putmapping , @deletemapping 在我的控制器处理程序方法中。
结果是错误消息:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:253)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:442)
谷歌搜索后,我找到了这个解决方案,以以下方式添加所需的bean,确实有效:
@Bean
public FilterRegistrationBean<HiddenHttpMethodFilter> hiddenHttpMethodFilter() {
FilterRegistrationBean<HiddenHttpMethodFilter> filterRegistrationBean = new FilterRegistrationBean<>(new HiddenHttpMethodFilter());
filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
return filterRegistrationBean;
}
我想知道为什么这种配置“ spring.mvc.hiddenmethod.filter 。
有人可以帮助我吗? 非常感谢
I use Spring Boot v2.7.0, installed from "start.spring.io" and from there I installed Thymeleaf, and as I searched in the parent-pom I found out that:
thymeleaf-spring5 (v3.0.15.RELEASE), thymeleaf-extras-java8time (v3.0.4.RELEASE)
Lately, I needed to apply the pattern <form th:method="put/delete".../>.
After googling in verious places, I found the solution, which was reffered in the book as well:
"Taming Thymeleaf Practical Guide to building a web application with Spring Boot and Thymeleaf - Wim Deblauwe"
which is the top/excellent books of Thymeleaf, and from which I learn Thymeleaf.
Acoording to these, I did:
Step 1:
Added this property in application.properties:
spring.mvc.hiddenmethod.filter.enabled=true
and I tried it in the application.yaml (as a 2nd solution, because the previous did not work), like this way:
spring:
mvc:
hiddenmethod:
filter:
enabled: true
Step 2:
I used:
<form th:method="put".../>
<form th:method="delete".../>
Step 3:
Finally I used the: "@PutMapping, @DeleteMapping" in my controller handler methods.
The result was the error message:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:253)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:442)
After googling I found this solution, to add the needed bean by myself with the following way, which DID WORKED:
@Bean
public FilterRegistrationBean<HiddenHttpMethodFilter> hiddenHttpMethodFilter() {
FilterRegistrationBean<HiddenHttpMethodFilter> filterRegistrationBean = new FilterRegistrationBean<>(new HiddenHttpMethodFilter());
filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
return filterRegistrationBean;
}
I wonder why this configuration "spring.mvc.hiddenmethod.filter.enabled=true", does not add the needed bean in my case, and I have to add it by myself.
Anyone can help me on this, please?
Thanks a lot in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己只是进行了测试,这很好。
使用此表单数据类:
index.html
preationsrc中的
file /main/resources/templates :application.properties
要包含:@putMapping
工作。I just did a test myself and this worked fine.
With this form data class:
index.html
file insrc/main/resources/templates
:application.properties
to contain:@PutMapping
works.