【发布时间】:2019-03-22 17:10:02
【问题描述】:
有谁知道如何在 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>
我在模型中将此变量设置为私有布尔直接框。
我已经尝试了所有方法:th:checked=checked、value=true、value=checked、设置值和checked ="${directBox}" 这些都不起作用。
有解决办法吗?
【问题讨论】:
-
如果你想使用
th:field,你可能需要改变你的控制器。看到这个线程:forum.thymeleaf.org/… -
你知道如果我不使用 th:field (和 th:name 代替),我怎样才能让 th:text 通过电子邮件发送值?我所有的其他表单元素都是 th:field,在电子邮件助手上,我将其作为 th:text 来读取每个输入的答案。
标签: java spring-boot thymeleaf