如何在百里香中过滤出一个集合
问题内容:
我正在尝试按照以下网址中的示例过滤使用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
希望有帮助