如何使用Thymeleaf在表单中为输入设置检查属性? 这是我的代码,目前不起作用:
<label th:each="cat : ${categories}">
<input type="checkbox" value=""
th:value="${cat.id}"
th:text="${cat.description}"
th:checked="${recipe.getCategories().contains(cat) ? true : false}"
/>
</label>
答案 0 :(得分:0)
如评论中所述,问题可能出在其他地方,请尝试一下并查看是否有帮助:
th:checked="${recipe.getCategories().contains(cat)}"