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.