我收到一封信 Request method 'POST' not supported error
每次我按下按钮
eventcontroller.java片段
@PostMapping(value = "/ledger/{id}/get-place")
public String modifyLedger(@PathVariable(value = "id") long id, @RequestParam Long place, Model model) {
Event event = eventRepository.findById(id).orElseThrow();
event.setPlace(place - 1);
eventRepository.save(event);
return "ledgerInfo";
}
这个函数假设从 Long place
每次我按下按钮时都是可变的但是每次我得到一个 HttpRequestMethodNotSupportedException
错误
账本信息.html
<div class = "container mt-5">
<h1>Ledger Info</h1>
<div th:each="elem:${event}" class="alert alert-info mt-2">
<h2 th:text="${elem.title}"/>
Line count:<p th:text="${elem.line}"/>
Place remain:<p th:text="${elem.place}"/>
Place status:<p th:text="${elem.status}"/>
<form method="post">
<button type="submit" class="btn btn-success">Get Place</button>
</form>
</div>
</div>
我不知道怎么解决这个问题。有什么线索吗?
1条答案
按热度按时间sigwle7e1#
您没有为窗体指定操作。在表单标签中使用th:action=“@{/your url}”。