Thymeleaf中选中的复选框属性

时间:2018-07-11 14:54:43

标签: spring-mvc thymeleaf

如何使用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>

1 个答案:

答案 0 :(得分:0)

如评论中所述,问题可能出在其他地方,请尝试一下并查看是否有帮助:

th:checked="${recipe.getCategories().contains(cat)}"