【发布时间】:2021-04-12 15:43:56
【问题描述】:
我每次按下按钮都会收到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 错误时
分类帐信息.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>
【问题讨论】:
标签: spring spring-boot thymeleaf