不能通过按下按钮更改列值(Spring启动,自动调整)

6psbrbz9  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(190)

我收到一封信 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>

我不知道怎么解决这个问题。有什么线索吗?

sigwle7e

sigwle7e1#

您没有为窗体指定操作。在表单标签中使用th:action=“@{/your url}”。

相关问题