Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twitter bootstrap 将th:each与themelaf一起使用并对空列表应用分区会抛出错误_Twitter Bootstrap_Spring Mvc_Thymeleaf - Fatal编程技术网

Twitter bootstrap 将th:each与themelaf一起使用并对空列表应用分区会抛出错误

Twitter bootstrap 将th:each与themelaf一起使用并对空列表应用分区会抛出错误,twitter-bootstrap,spring-mvc,thymeleaf,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 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" >

有没有解决这个问题的办法

您必须将
th:each
更改为:

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

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

我复制并粘贴了您的更改,但得到的错误是:HTTP状态500-请求处理失败;嵌套异常是org.thymeleaf.exceptions.TemplateProcessingException:exception评估SpringEL表达式:“T(com.google.common.collect.Lists).partition(hotels,#Lists.size(hotels))”是否使用缓存?清理并重新启动?嗨,帕特里克,我没有使用任何缓存。但仍然清除它并再次运行它。我也犯了同样的错误。我认为表达式T(com.google.common.collect.Lists).partition(hotels,#Lists.size(hotels))”存在问题,但还不能解决。奇怪的是,你能试着把一个固定的数字作为大小吗?即(4作为列表的大小):T(com.google.common.collect.Lists).partition(hotels,4)
th:each="hotelChunk : ${T(com.google.common.collect.Lists).partition(hotels, #lists.size(hotels))}"