thymeleaf下拉菜单、单选按钮、多选按钮的数据回显
程序员文章站
2022-05-01 23:14:02
...
1、单选按钮
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>性 别:</label>
<div class="formControls col-xs-8 col-sm-9 skin-minimal">
<div class="radio-box">
<input name="gender" type="radio" th:attr ="checked=${user.getGender()=='1'?true:false}" id="sex-1" value="0">
<label >男</label>
</div>
<div class="radio-box">
<input type="radio" th:attr ="checked=${user.getGender()=='0'?true:false}" id="sex-2" name="gender" value="1">
<label >女</label>
</div>
</div>
</div>
2、下拉框
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角 色:</label>
<div class="formControls col-xs-8 col-sm-9">
<span class="select-box">
<select class="select" id="rol" size="1" name="city" onchange="changerole()">
<option style="height: 50px;" th:selected="${role.getRoleid() eq user.getRole_id()}" th:each="role:${rolelist}">[[${role.rolename}]]</option>
</select>
</span>
</div>
<input style="display: none" id="role" value="" name="role">
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>权 限:</label>
<div class="formControls col-xs-8 col-sm-9">
<span class="select-box">
<select class="select" id="pri" name="" onchange="changeprivilege()">
<option style="height: 50px;" th:selected="${privilege.pid eq user.getPrivilege()}" th:each="privilege:${pList}">[[${privilege.pname}]]</option>
</select>
</span>
</div>
<input style="display: none" id="privilege" value="" name="privilege">
</div>
3、默认选中第一个
<input type ="radio" name="repaymentType"
th:each ="repaymentType,repaymentState:${repaymentTypeList}"
th:value="${repaymentType.dictName}"
th:text ="${repaymentType.dictName}"
th:attr ="checked=${repaymentState.index==0?true:false}">
4、多选
//多选回显
<div class="row cl">
<input type ="checkbox" name="role"
th:each ="role : ${roleList}"
th:value="${role.roleName}"
th:text ="${role.roleName}"
th:attr ="checked=${userinfo.userRole.contains(role.roleName)?true:false}">
</div>