Using Thymeleaf, I felt "Is there such a usage?", So I will describe it.
For example, the same form is specified as shown below ('/ reservations /'+ $ {date} +'/' + $ {roomId}} ") But suppose you want to separate the processes.
index.html
<form th:action="@{'/reservations/' + ${date} + '/' + ${roomId}}" method="post"
sec:authorize="${hasRole('ADMIN') or #vars.user.userId==#vars.reservation.user.userId}">
<!-- th:if="${user.userId==reservation.user.userId}" -->
<input type="hidden" name="reservationId" th:value="${reservation.reservationId}">
<input type="submit" name="cancel" value="cancel">
</form>
<form th:action="@{'/reservations/' + ${date} + '/' + ${roomId}}" method="post">
<input type="text" name="userId">
<input type="submit" name="search" value="Search">
</form>
Prepare name = "XXXX" as an option of input tag, By specifying (params = "XXXX") in the @GetMapping or @PostMapping option of the Controller You can separate the processing.
index.html
<input type="submit" name="search" value="Search">
Controller.java
@PostMapping(params="search")
public String search(@RequestParam("userId") String userId, Model model) {
List<Reservation> lists = reservationService.find(userId);
model.addAttribute("list", lists);
return "test";
}
Recommended Posts