以下是下拉框和单选框的相关代码,仅供参考。
下拉框
<div class="form-group mb">
<label class="col-sm-2 control-label">学校 *</label>
<div class="col-sm-8">
<select name="schoolId" class="form-control m-b">
<option th:each="school:${schoolList}"
th:text="${school.name}"
th:value="${school.id}"
th:selected="${student.schoolId==school.id}">
</option>
</select>
</div>
</div>
(session补充)在“新增页面”和“编辑页面”中增加如下代码,以显示下拉框内的内容
//查询学校
List<School> schoolList = this.schoolService.query();
model.addAttribute("schoolList", schoolList);
单选框
<div class="form-group mb">
<label class="control-label col-sm-2">性别 *</label>
<div class="col-sm-8">
<th:block th:if="${student.sex=='男'}">
<label class="radio-inline c-radio">
<input id="sex1" type="radio" name="sex" value="男" checked="checked"/>
<span class="fa fa-circle"></span>男
</label>
<label class="radio-inline c-radio">
<input id="sex2" type="radio" name="sex" value="女" />
<span class="fa fa-circle"></span>女
</label>
</th:block>
<th:block th:if="${student.sex=='女'}">
<label class="radio-inline c-radio">
<input id="sex1" type="radio" name="sex" value="男" />
<span class="fa fa-circle"></span>男
</label>
<label class="radio-inline c-radio">
<input id="sex2" type="radio" name="sex" value="女" checked="checked"/>
<span class="fa fa-circle"></span>女
</label>
</th:block>
<th:block th:if="${student.sex==null}">
<label class="radio-inline c-radio">
<input id="sex1" type="radio" name="sex" value="男"/>
<span class="fa fa-circle"></span>男
</label>
<label class="radio-inline c-radio">
<input id="sex2" type="radio" name="sex" value="女"/>
<span class="fa fa-circle"></span>女
</label>
</th:block>
</div>
</div>