"th:each"用於迭代遍歷
<table> <thead> <tr> <th>序號</th> <th>用戶名</th> <th>密碼</th> <th>用戶昵稱</th> </tr> <tr th:each="user:${userlist}"> <td th:text="${user.id}"></td> <td th:text="${user.username}"></td> <td th:text="${user.password}"></td> <td th:text="${user.petname}"></td> </tr> </thead> </table>
迭代下標變量用法:
狀態變量定義在一個th:每個屬性和包含以下數據:
1.當前迭代索引,從0開始。這是索引屬性。index
2.當前迭代索引,從1開始。這是統計屬性。count
3.元素的總量迭代變量。這是大小屬性。 size
4.iter變量為每個迭代。這是目前的財產。 current
5.是否當前迭代是奇數還是偶數。這些even/odd的布爾屬性。
6.是否第一個當前迭代。這是first布爾屬性。
7.是否最后一個當前迭代。這是last布爾屬性。
一個實例
<table > <thead> <tr > <th>序號</th> <th>教師姓名</th> <th>教師性別</th> <th>教師工號</th> </tr> </thead> <tbody> <tr th:each="teacher,count:${teachers.list}"> <td th:text="${count.count}"></td> <td th:text="${teacher.teacherName}"></td> <td th:text="${teacher.teacherSex}"></td> <td th:text="${teacher.teacherNo}"></td> </tr> </tbody> </table>
第一列是一個從1開始的序號列
"th:if"用於判斷 用法: th:if="${xx} lt 'x'" <-----------> xx < x 1 thymeleaf 判斷表達式: gt:great than(大於)> ge:great equal(大於等於)>= eq:equal(等於)== lt:less than(小於)< le:less equal(小於等於)<= ne:not equal(不等於)!=
一個實例
<tr th:each="user:${users}"> <td th:if="${user.num} eq '123'" th:text="${user.username}"> </td> </tr>
————————————————
版權聲明:本文為CSDN博主「一只有理想的程序員」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/flying_hengfei/java/article/details/103077172