【发布时间】:2017-09-21 17:40:36
【问题描述】:
我在 Thymeleaf 和 Spring 中有以下代码。对于某些列表,我具有所选选项的值会填充整个对象,但对于某些列表则没有。
public class BeneficiaryUploadCommand {
private List<SchemeCommand> schemeCommandList;
private List<BudgetHeads> budgetHeadsList;
@NotEmpty
private List<BeneficiaryType> beneficiaryTypeLists;
@NotEmpty
private List<FinancialYear> financialYearList;
@NotEmpty
private List<SubSchemes> subSchemesList;
private Date toDate;
private Date fromDate;
@Size(min=10, max = 10)
private String toDate1;
@Size(min=10, max = 10)
private String fromDate1;
@NotEmpty
private List<BenefitType> benefitTypesList;
@NotNull
private Integer beneficiariesProposed;
@NotNull
private Double stateShare;
private Double actualExpenditure;
@NotNull
private Double advancedExpenditure;
@NotNull
private char aadharLinkedOrNot;
@NotNull
private char cropItemDataAvailable;
@NotNull
private String schemeCommandId;
@NotNull
private String budgetHeadsListId;
}
Thymeleaf 代码如下:
<select id="financialYearListId" th:field="*{financialYearList}" style="width:100px; float:left;" >
<option th:value="0" th:text=" Select "></option>
<th:block th:each="finYear : ${beneficiaryData.financialYearList}">
<option th:value="${finYear.id}" th:text="${finYear.financialYear}" label=" - Select - "></option>
</th:block>
</select>
</td>
<td colspan="1" align="right"><font color="red">*</font>
<b>From Date</b>
</td>
<td colspan="1">
<input type="text" th:field="*{fromDate1}" name="from_date" class="date form-control" style="width: 100px; margin: 0px;"/>
</td>
<td colspan="1" align="right"><font color="red">*</font>
<b>To Date</b>
</td>
<td colspan="1">
<input type="text" th:field="*{toDate1}" name="to_date" class="date form-control" style="width: 100px; margin: 0px;"/>
</td>
</tr>
<tr>
<td colspan="1"><font color="red">*</font> <b>Scheme</b></td>
<td colspan="1" width="20%">
<select th:field="*{schemeCommandId}" name="scheme_id" style="width:250px" th:onchange="'getSubSchemesandBudgetHeads(this.value);'">
<th:block th:each="scheme : ${beneficiaryData.schemeCommandList}">
<option th:value="${scheme.id}" th:text="${scheme.schemeName}" label=" - Select - " />
</th:block>
</select>
现在当我选择th:field="*{financialYearList}"
填充List 对象的整个financialyear 对象。但是对于schemeCommandList,它只给出id?我很困惑如何将某些对象整体转换,而有些对象只提供 id。
【问题讨论】:
标签: spring-mvc thymeleaf