请求方法' post'胸腺不支持错误的错误:方法=;

发布于 2025-02-11 06:50:36 字数 1073 浏览 1 评论 0 原文

提交以下表格后,我有一个错误:

存在意外错误(类型=不允许的方法,状态= 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鞋纸虽美,但不合脚ㄋ〞 2025-02-18 06:50:36

html delete http方法的方法属性。

当您使用 th:method =“ put” 胸膜eak将创建隐藏的输入如下屏幕截图,然后将方法值更改为 post

由于此更改, @putMapping 默认情况下不起作用,但是如果您执行 @postMaping 会。

如果要使用 @putMapping

您可以通过添加 spring.mvc.hiddenmethod.filter.filter.enabled = true 来启用此功能。您的 application.properties 文件。请参阅 Spring启动如何使用Sideenshttpmethodfilter

HTML does not support PUT or DELETE HTTP methods for its method attribute.

When you use th:method="PUT" thymeleaf will create hidden input as below screenshot and changes method value to POST.

Because of this change, @PutMapping does not work by default, but if you do @PostMaping it will.

enter image description here

If you want to use it with @PutMapping:

You can enable this by adding spring.mvc.hiddenmethod.filter.enabled=true to your application.properties file. See Spring Boot how to use HiddenHttpMethodFilter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文