使用th:每个使用Themeleaf并在空列表上应用分区抛出错误

时间:2015-06-30 16:25:43

标签: twitter-bootstrap spring-mvc thymeleaf

迭代酒店列表。每当列表为空时它给我错误

     <div class="row list" th:if="${#lists.size(hotels) > 0}" th:each="hotelChunk : ${T(com.google.common.collect.Lists).partition(hotels, ${#lists.size(hotels)})}">
                <!-- single result item -->
                <div th:each="hotel : ${hotelChunk}"  class="col-md-4 single-result" >

错误是:

HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "T(com.google.common.collect.Lists).partition(hotels, ${#lists.size(hotels)})" (search:44)

有任何解决方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您必须将th:each更改为:

th:each="hotelChunk : ${T(com.google.common.collect.Lists).partition(hotels, #lists.size(hotels))}"

在当前的Thymeleaf表达式中不需要再次使用${..}