提交以下表格后,我有一个错误:
存在意外错误(类型=不允许的方法,状态= 405)。
请求方法“帖子”不支持
org.springframework.web.httprequestmethodnotsupportedexception:
请求方法“ post”不支持
是 thymeleaf form html标签:
<form th:method="put" action="/orders/3" th:object="${order}">
...
</form>
和控制器:
@PutMapping("/{id}")
public String update(@PathVariable("id") Long id,
@ModelAttribute(name = "order") OrderDto order) {
...
return "redirect:/orders";
}
当我更改 @put> @putmapping(“/{id}}”时(“/{id}”)
to @@ Postmapping(“/{ID}”)
错误修复了错误,为什么它不识别与 @putmapping
注释相关的控制器相关的方法?
更新:
此链接没有解决我的问题,因为我使用 th:method
method 属性,然后生成了 post
的html带有 put
值的隐藏输入的方法。如果我必须使用 @postmapping
注释,我想知道 @putmapping
usage。
I've got this error after I submit following form:
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
Here is Thymeleaf form html tag:
<form th:method="put" action="/orders/3" th:object="${order}">
...
</form>
And the controller:
@PutMapping("/{id}")
public String update(@PathVariable("id") Long id,
@ModelAttribute(name = "order") OrderDto order) {
...
return "redirect:/orders";
}
When I change @PutMapping("/{id}")
to @PostMapping("/{id}")
the error fix but why it's not recognize controller related method with @PutMapping
annotation?
UPDATE:
This link spring+ thymeleaf unable to update does not fix my problem, because I'm using th:method
not method
property and then it's generated html containing POST
method with hidden input with PUT
value. If I have to use @PostMapping
annotation I want to know @PutMapping
usage.
发布评论
评论(1)
html 或
delete
http方法的方法
属性。当您使用
th:method =“ put”
胸膜eak将创建隐藏的输入如下屏幕截图,然后将方法值更改为post
。由于此更改,
@putMapping
默认情况下不起作用,但是如果您执行@postMaping
会。如果要使用
@putMapping
:您可以通过添加
spring.mvc.hiddenmethod.filter.filter.enabled = true
来启用此功能。您的application.properties
文件。请参阅 Spring启动如何使用SideenshttpmethodfilterHTML does not support
PUT
orDELETE
HTTP methods for itsmethod
attribute.When you use
th:method="PUT"
thymeleaf will create hidden input as below screenshot and changes method value toPOST
.Because of this change,
@PutMapping
does not work by default, but if you do@PostMaping
it will.If you want to use it with
@PutMapping
:You can enable this by adding
spring.mvc.hiddenmethod.filter.enabled=true
to yourapplication.properties
file. See Spring Boot how to use HiddenHttpMethodFilter