有人知道如何在Thymeleaf,SpringBoot,Java项目中添加checked的默认设置到单个复选框的输入字段中吗?我必须使用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}",这些都不起作用。
有什么解决方案吗?
发布于 2018-10-20 02:50:39
找到了使用th:字段的方法,并将其默认设置为选中。必须在我的控制器中设置它,就像Gustavo提到的那样。下面是代码示例。
...
directBind.setDirectBox(true);
directBind.setServiceLevel(true);
model.addAttribute("directBind", directBind);
return "directBind";https://stackoverflow.com/questions/52864744
复制相似问题