thymeleaf单选回显,多选回显,选回显,下拉默认选中第一个

//默认选中第一个
<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}">

//单选回显
<input type="radio" name="repaymentType"
th:each ="repaymentType:${repaymentTypeList}"
th:value="${repaymentType.dictName}"
th:text ="${repaymentType.dictName}"
th:attr ="checked=${financeProductDO.repaymentType == repaymentType.dictName?true:false}">

//多选回显
<input type ="checkbox" name="companyRole"
th:each ="role : ${companyRoleList}"
th:value="${role.dictName}"
th:text ="${role.dictName}"
th:attr ="checked=${companyInformation.companyRole.contains(role.dictName)?true:false}">

//下拉选回显默认选中 前台接收到参数:user对象和businessList集合
<option th:selected="${user.businessId eq busi.businessId}"
th:each="busi:${businessList}"
th:value="${busi.businessId}"
th:text="${busi.businessName}" >
</option>

当你的才华还撑不起你的野心时
那你就应该静下心来学习
当你的能力还驾驭不了你的目标时
那就应该沉下心来历练
原文地址:https://www.cnblogs.com/yang-xiansen/p/10251357.html