Thymeleaf判斷集合是否為空
最近項目使用的是thymeleaf。項目架構是Springboot+Thymeleaf。
在判斷集合是否為空的時候踩了坑與大家分享。
以下代碼是判斷集合是否為空的,myCart是集合。
<div th:if="${#lists.isEmpty(myCart)}" ></div>
反之判斷集合不是空的判斷
<div th:if="${not #lists.isEmpty(myCart)}"></div>
或者
<div th:if="not ${#lists.isEmpty(myCart)}"></div>
需要提醒的是 th:if做判斷之后是不可以在后面直接寫循環的不然即便th:if為false th:each還是會執行的。
原文地址:http://www.dandelioncloud.cn/article/details/609045327238970