Java 对于Thymeleaf和Spring MVC,表单值为空
我正在尝试用Thymeleaf和SpringMVC处理表单。 用户应选择一个预订,然后将其保存在表单中 模板如下所示:Java 对于Thymeleaf和Spring MVC,表单值为空,java,forms,spring-mvc,thymeleaf,Java,Forms,Spring Mvc,Thymeleaf,我正在尝试用Thymeleaf和SpringMVC处理表单。 用户应选择一个预订,然后将其保存在表单中 模板如下所示: <form action="#" th:object="${reservationselectionform}"> <select th:field="*{reservationSelection}" class="selectpicker" data-live-search="true" style="display: no
<form action="#" th:object="${reservationselectionform}">
<select th:field="*{reservationSelection}" class="selectpicker" data-live-search="true" style="display: none;" >
<option th:each="reservation : ${reservationlist}"
th:value="${reservation}"
th:text="${reservation.user.userAccount.firstname}">Tyler Durden</option>
</select>
<button type="submit" class="btn btn-primary" formaction="/checkintest" formmethod="post">Weiter</button>
@RequestMapping(value="choose_reservation", method = RequestMethod.GET)
public String chose_reservation(ModelMap modelMap{
modelMap.addAttribute("reservationselectionform", new ReservationSelectionForm());
return "checkin/choose_reservation";
}
@RequestMapping("/checkintest")
public String personaldata (ModelMap modelMap,
@ModelAttribute("reservationselectionform") ReservationSelectionForm reservationSelectionForm){
return "checkin/checkintest";
}
表格很简单,如下所示:
public class ReservationSelectionForm {
private Reservation reservationSelection;
@NotEmpty
private String firstname;
@NotEmpty
private String lastname;
//getter & setter
如果我尝试使用表单设置firstname,则firstname会完全包含在ReservationSelectionForm中
当我传递整个预订对象(th:value=“${Reservation}”)
时,它在ReservationSelectionForm中总是null
有人能给我解释一下,或者帮我传递整个预订对象吗?您的选择列表总是空的。