Html 如何在thymeleaf th中筛选集合:每个集合使用另一个属性进行比较
我试图通过以下url中的示例,使用Thymeleaf过滤集合。 “集合上的投影和选择”部分。Html 如何在thymeleaf th中筛选集合:每个集合使用另一个属性进行比较,html,spring-mvc,thymeleaf,spring-el,Html,Spring Mvc,Thymeleaf,Spring El,我试图通过以下url中的示例,使用Thymeleaf过滤集合。 “集合上的投影和选择”部分。 ... 但是,我希望使用另一个属性而不是固定值(true/false)。比如说 <tr th:each="artist,rowStat : ${listArtits.?[played > playedCountReq]}"> ... </tr> ... 其中as playedCountReq是Thymeleaf可用的另一个表单变量。我得到以下错误。在类型为的对象
...
但是,我希望使用另一个属性而不是固定值(true/false)。比如说
<tr th:each="artist,rowStat : ${listArtits.?[played > playedCountReq]}">
...
</tr>
...
其中as playedCountReq是Thymeleaf可用的另一个表单变量。我得到以下错误。在类型为的对象上找不到属性或字段“playedCountReq”
我尝试了多种方法,但没有成功。有什么建议吗?我成功了:)以下是解决方案:
在控制器中:
(...)
Person p1 = new Person();
p1.setAge(20);
Person p2 = new Person();
p2.setAge(30);
List<Person> list = Lists.newArrayList(p1,p2);
modelMap.addAttribute("list", list);
Integer minAge = 13;
modelMap.addAttribute("minAge", minAge);
(...)
希望获得此帮助在选择筛选器中,非限定属性与要筛选的集合元素相关。但是,变量
#root
始终被定义为根上下文对象。这就是如何从选择过滤器中引用根级别的变量
<tr th:each="artist,rowStat : ${listArtists.?[played gt #root.playedCountReq]}">
…
</tr>
…
有关更多信息,请参阅Spring EL文档中的“”部分。到目前为止,我找到的唯一解决方法是使用th:block。在th:block中移动th:each,如果在tr标记中,请输入整个表单/表格的代码,这样我们可以看到完整的图片
<table th:with="min=${minAge}">
<tr th:each="person,rowStat : ${list.?[age > __${min}__]}">
<td><span th:text="${person.age}"></span></td>
</tr>
</table>
30
<tr th:each="artist,rowStat : ${listArtists.?[played gt #root.playedCountReq]}">
…
</tr>