2
Thymeleaf唯一块级标签th:block使用(标签本身不显示)
source link: https://blog.51cto.com/abcd/6047226
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Thymeleaf唯一块级标签th:block使用(标签本身不显示)
精选 原创th:block是一个属性容器,是Thymeleaf提供的唯一的一个块级元素,可以使用<th:block></th:block>定义片断块,并在里面添加任何的th属性;
特殊性在于Thymeleaf模板引擎在处理th:block的时候会删掉它本身,标签本身不显示,而保留其内容,在循环的时候特别有用。
<th:block>
</th:block>
</th:block>
比如说循环输出一个表格行的内容
<table>
<th:block th:each="user:${userList}">
<tr>
<td th:text="${user.userId}"></td>
<td th:text="${user.userName}"></td>
<td th:text="${user.userAge}"></td>
<td th:text="${user.userSex ? '男':'女'}"></td>
</tr>
</th:block>
</table>
<th:block th:each="user:${userList}">
<tr>
<td th:text="${user.userId}"></td>
<td th:text="${user.userName}"></td>
<td th:text="${user.userAge}"></td>
<td th:text="${user.userSex ? '男':'女'}"></td>
</tr>
</th:block>
</table>
- 打赏
- 赞
- 收藏
- 评论
- 分享
- 举报
上一篇:Java中调用js方法
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK