有谁知道如何在Thymeleaf,SpringBoot,Java项目中将checked
的默认设置添加到Single复选框的输入字段中?我必须使用th:field
,因为我稍后通过电子邮件提交此表单,如果我使用带有复选框默认值的th:name
,则默认有效但电子邮件不能。
有什么建议?
<label>
<input type="checkbox" id="serviceLevel" th:field="*{serviceLevel}" th:checked="${serviceLevel}"/>
Affiliate Serviced</label>
通过电子邮件发送html代码来提取电子邮
<tr class="emailRow">
<h3>Direct: </h3>
<td class="bodycopy" th:text="${directBind.directBox}">
</td>
</tr>
我将此变量设置为模型中的私有布尔值directBox。
我已经尝试了一切:th:checked=checked
,value=true
,value=checked
,设置值和checked ="${directBox}"
没有这个工作。
那里有解决方案吗?
想出了一种使用th:field的方法,并默认选中它。必须在我的控制器中设置它,就像Gustavo提到的那样。代码示例如下。
...
directBind.setDirectBox(true);
directBind.setServiceLevel(true);
model.addAttribute("directBind", directBind);
return "directBind";