每次按下按钮时,我都会得到一个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
变量中减去1,但每次我得到HttpRequestMethodNotSupportedException
错误
LedgerInfo.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>
不知道如何解决这个问题。有线索吗?
您没有为表单指定操作。使用th:action="@{/您的Url}"在表单标签中。