【发布时间】:2016-01-26 14:41:03
【问题描述】:
我有一个包含所有字段的表单,其中少一个,由用户填写。这是通过表单传递的类
public class CarForm {
private String id;
private Integer initialKm;
private String carChassis;
private String note;
private String carType;
private Integer fleet;
只有一个字段,fleet,我想在传递表单之前设置,或者更好的是,从 HTML 设置它。例如:
<div class="form-group">
<label>Fleet application</label> <input type="text"
class="form-control" th:field="*{fleet}"
th:placeholder="${fleetApplication}" readonly="readonly">
</div>
所以我想显示${fleetApplication.application} 并将此值设置为fleet,或者,如果可能,设置另一个值${fleetApplication.idFleet}。
是否有可能是这些解决方案之一?谢谢
更新:正如@Faraj Farook 所建议的,我这样解决了:
<div class="form-group">
<label>Fleet application</label>
<!-- Show fleet application -->
<input class="form-control" type="text" th:value="${fleetApplication.application}" readonly="readonly" />
<!-- Save into fleet the value of idFleet -->
<input type="hidden" name="fleet" th:value="${fleetApplication.idFleet}" />
</div>
【问题讨论】:
标签: html forms spring-mvc thymeleaf