【发布时间】:2020-09-01 03:28:05
【问题描述】:
在我的 Spring Boot 应用程序中,我正在努力填充选择下拉菜单。我的页面是显示选择下拉代码如下
<form th:action="@{/payment}" modelAttribute="homeFormBean" th:object="${homeFormBean}" method="POST">
<section id="cover" class="min-vh-100">
<div id="cover-caption">
<div class="container">
<div class="row text-black">
<div class="col-xl-5 col-lg-6 col-md-12 col-sm-10 mx-auto text-center form p-4">
<div class="col-md-12 form-group">
<label>Type</label>
<select class="form-control" th:field="*{selectedPaymentType}">
<option value="">Choose...</option>
<option th:each="paymentServiceType : ${paymentServiceTypeList}"
th:value="${paymentServiceType.code}"
th:utext="${paymentServiceType.description}"/>
</select>
</div>
<div class="col-md-12">
<label>From Date</label>
<input type="datetime-local" class="form-control" th:name="fromDate">
</div>
<div class="col-md-12">
<label>To Date</label>
<input type="datetime-local" class="form-control" th:name="toDate">
</div>
<div class="form-group container">
<br/>
<button type="submit" class="btn btn-primary btn-lg">Go</button>
</div>
</div>
</div>
</div>
</div>
</section>
</form>
HomeFormBean 对象具有以下属性
private List<Lookup> paymentServiceTypeList;
private String selectedPaymentType;
private String fromDate;
private String toDate;
页面加载时model属性设置如下
//this.userPaymentLookupList has the drop down values.
HomeFormBean homeFormBean = new HomeFormBean();
homeFormBean.setPaymentServiceTypeList(this.userPaymentLookupList);
model.addAttribute("homeFormBean", homeFormBean);
完成所有这些后,我的选择选项仍然没有填充值。我搞砸了什么?
【问题讨论】:
标签: spring-boot thymeleaf