首页 > 解决方案 > Thymeleaf (th:each + th:selected) :从每个循环访问选定属性中的变量

问题描述

如果某个列表包含来自每个循环的值,我想选择选项标签。但是从选定属性的循环中访问变量存在一些问题。这是我的代码:

<option th:each="facility: ${facilities}" th:value="${facility.id}" th:text="${facility.name}" th:selected="${apartment.facilities.contains(facility.id)}"></option>

下一个代码也不起作用:th:selected="${#lists.contains(apartment.facilities, facility.id)}"

它适用于th:selected="${apartment.facilities.contains(SOME_DIGIT)}"and th:selected="${facility.id == SOME_DIGIT}"。怎么了?

标签: javaspringthymeleafserver-sidetemplate-engine

解决方案


解决方案:有不同的类型。List 包含 int 值,但我检查过 contains 的值类型很长。


推荐阅读