thymeleaf標簽 th:each的使用


<div class="item active"  th:if="${iterStat.index==0}" th:each="img,iterStat:${pics}">

  <img th:src="${img.path}" style="width: 303px;height: 171px;"/>

</div>
解說:
  對arrayList對象pics遍歷,使用img作為接受參數接收,使用iterStat作為pics下標值,通過iterStat.index得到當前所處下標值;
  通過th:src="${img.path}"得到對象中圖片路徑設置圖片顯示圖

<tr th:each="prod,iterStat : ${prods}" th:class="${iterStat.odd}? 'odd'"> <td th:text="${prod.name}">Onions</td> <td th:text="${prod.price}">2.41</td> <td th:text="${prod.inStock}? #{true} : #{false}">yes</td> </tr>

解說:
  判斷下標是否未奇數,設置tr樣式

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM