thymeleaf 遍歷使用案例


1、語法:

th:each屬性用於迭代循環,語法:th:each="obj,iterStat:${objList}"

迭代對象可以是List,Map,數組等;

2、說明:iterStat稱作狀態變量,屬性有:
    index:當前迭代對象的index(從0開始計算)
    count: 當前迭代對象的index(從1開始計算)
    size:被迭代對象的大小
    current:當前迭代變量
    even/odd:布爾值,當前循環是否是偶數/奇數(從0開始計算)
    first:布爾值,當前循環是否是第一個

    last:布爾值,當前循環是否是最后一個

3、示例: 

<html>
 <head></head>
 <body>
  <li>List遍歷: 
   <table border="1"> 
    <tbody>
     <tr>
      <th>名稱</th> 
      <th>狀態變量:index</th>
   ...
</tr> <tr th:each="user,userStat : ${userList}"> <th th:text="${user.name}">test</th> <th th:text="${userStat.index}">狀態變量:index</th> ... </tr> </tbody> </table> </li> <li>Map遍歷: <div th:each="map:${maps}"> <div th:text="${map}"></div> </div> </li> <li>數組遍歷: <div th:each="array:${arrays}"> <div th:text="${array}"></div> </div> </li> </body> </html>     


免責聲明!

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



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