一、語法:html
th:each屬性用於迭代循環,語法:th:each="obj,iterStat:${objList}"數組
迭代對象能夠是List,Map,數組等;spa
二、說明:iterStat稱做狀態變量,屬性有:
index:當前迭代對象的index(從0開始計算)
count: 當前迭代對象的index(從1開始計算)
size:被迭代對象的大小
current:當前迭代變量
even/odd:布爾值,當前循環是不是偶數/奇數(從0開始計算)
first:布爾值,當前循環是不是第一個code
last:布爾值,當前循環是不是最後一個htm
三、示例: 對象
<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>