如何在thymeleaf中过滤集合:每个都使用另一个属性进行比较 [英] How to filter a collection in thymeleaf th:each using another property in comparison
问题描述
我正在尝试按照以下网址中的示例使用Thymeleaf过滤集合. 对投影进行投影和选择"部分. http://doanduyhai.wordpress. com/2012/04/14/spring-mvc-part-iv-thymeleaf-advanced-usage/
<tr th:each="artist,rowStat : ${listArtits.?[alive == true]}">
...
</tr>
但是,我想使用另一个属性而不是固定值(true/false).例如
<tr th:each="artist,rowStat : ${listArtits.?[played > playedCountReq]}">
...
</tr>
其中,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);
(...)
在html中:
<table th:with="min=${minAge}">
<tr th:each="person,rowStat : ${list.?[age > __${min}__]}">
<td><span th:text="${person.age}"></span></td>
</tr>
</table>
输出:
30
希望获得帮助
I am trying to filter the collection using Thymeleaf by following the example in the following url. "Projection & selection on collection" section. http://doanduyhai.wordpress.com/2012/04/14/spring-mvc-part-iv-thymeleaf-advanced-usage/
<tr th:each="artist,rowStat : ${listArtits.?[alive == true]}">
...
</tr>
However I would like to use another property instead of fixed value (true/false). For example
<tr th:each="artist,rowStat : ${listArtits.?[played > playedCountReq]}">
...
</tr>
where as playedCountReq is another form variable available to Thymeleaf. I get the following error. Property or field 'playedCountReq' cannot be found on object of type ...
I tried multiple ways but no success. Any suggestions?
I succeded :) Here is solution:
in controller:
(...)
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);
(...)
in html:
<table th:with="min=${minAge}">
<tr th:each="person,rowStat : ${list.?[age > __${min}__]}">
<td><span th:text="${person.age}"></span></td>
</tr>
</table>
Output:
30
Hope this help
这篇关于如何在thymeleaf中过滤集合:每个都使用另一个属性进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!