复选框回显 th:checked
thymeleaf复选框回显 th:checked
第一种:
<label class="checkbox-inline check-box" th:each="dict : ${@dict.getType('valid_complaints')}">
<input
type="checkbox" th:value="${dict.dictValue}"
th:text="${dict.dictLabel}"
name="fqzdcInvestigateAppraise.validComplaints"
th:if="${investigateMain.fqzdcInvestigateAppraise.validComplaints!=null}"
th:attr ="checked=${investigateMain.fqzdcInvestigateAppraise.validComplaints.contains(dict.dictValue)?true:false}"
>
<input
type="checkbox" th:value="${dict.dictValue}"
th:text="${dict.dictLabel}"
name="fqzdcInvestigateAppraise.validComplaints"
th:if="${investigateMain.fqzdcInvestigateAppraise.validComplaints==null}"
>
</label>
直接添加:
th:attr =“checked=${investigateMain.fqzdcInvestigateAppraise.validComplaints.contains(dict.dictValue)?true:false}” 在页面显示出来
第二种:
<label class="checkbox-inline check-box" th:each="dict : ${@dict.getType('valid_complaints')}">
<input
type="checkbox" th:value="${dict.dictValue}"
th:text="${dict.dictLabel}"
name="fqzdcInvestigateAppraise.validComplaints"
th:if="${investigateMain.fqzdcInvestigateAppraise.validComplaints!=null}"
th:checked="${#arrays.contains(#strings.arraySplit(investigateMain.fqzdcInvestigateAppraise.validComplaints,','),#strings.toString(dict.dictValue))}"
>
<input
type="checkbox" th:value="${dict.dictValue}"
th:text="${dict.dictLabel}"
name="fqzdcInvestigateAppraise.validComplaints"
th:if="${investigateMain.fqzdcInvestigateAppraise.validComplaints==null}"
>
</label>
直接添加:
th:checked="${#arrays.contains(#strings.arraySplit(investigateMain.fqzdcInvestigateAppraise.validComplaints,’,’),#strings.toString(dict.dictValue))}",其中investigateMain.fqzdcInvestigateAppraise.validComplaints 是你的业务代码值,比如a,b,c.