thymeleaf的th:each常见用法

简介: thymeleaf的th:each常见用法一.th:eath迭代集合用法: 是否选中 编号 姓名 年龄 编号 姓名 年龄 二.迭代下标变量用法:状态变量定义在一个th:每个属性和包含以下数据:1.当前迭代索引,从0开始。

thymeleaf的th:each常见用法

一.th:eath迭代集合用法:

<table border="1" id="stuTable">
    <tr>
        <td>是否选中</td>
        <td>编号</td>
        <td>姓名</td>
        <td>年龄</td>
    </tr>
    <tr th:each="stu,userStat:${studentList}" >
        <td><input th:type="checkbox" th:name="id" th:value="${stu.id}"></td>
        <td th:text="${stu.id}">编号</td>
        <td th:text="${stu.name}">姓名</td>
        <td th:text="${stu.age}">年龄</td>
    </tr>
</table>

二.迭代下标变量用法:

状态变量定义在一个th:每个属性和包含以下数据:

1.当前迭代索引,从0开始。这是索引属性。index

2.当前迭代索引,从1开始。这是统计属性。count

3.元素的总量迭代变量。这是大小属性。 size

4.iter变量为每个迭代。这是目前的财产。 current

5.是否当前迭代是奇数还是偶数。这些even/odd的布尔属性。

6.是否第一个当前迭代。这是first布尔属性。

7.是否最后一个当前迭代。这是last布尔属性。

用法实例:

<table border="1" id="stuTable">
    <tr>
        <td>是否选中</td>
        <td>编号</td>
        <td>姓名</td>
        <td>年龄</td>
    </tr>
    <tr th:each="stu,userStat:${studentList}" th:class="${userStat.odd}?'odd':'even'">
        <td th:text="${userStat.index}"></td>
        <td><input th:type="checkbox" th:name="id" th:value="${stu.id}"></td>
        <td th:text="${stu.id}">编号</td>
        <td th:text="${stu.name}">姓名</td>
        <td th:text="${stu.age}">年龄</td>
    </tr>
</table>
相关文章
|
5月前
|
容器
Thymeleaf $/*/#/@语法
Thymeleaf $/*/#/@语法
|
8月前
|
前端开发 Java
SpringBoot-6-模板Thymeleaf常用标签
SpringBoot-6-模板Thymeleaf常用标签
44 0
SpringBoot-6-模板Thymeleaf常用标签
|
4月前
|
XML 前端开发 Java
Spring Boot的Web开发之Thymeleaf模板引擎的解析及使用(Thymeleaf的基础语法以及常用属性)
Spring Boot的Web开发之Thymeleaf模板引擎的解析及使用(Thymeleaf的基础语法以及常用属性)
58 0
|
4月前
|
前端开发 Java Linux
Thymeleaf - 语法使用详解
Thymeleaf - 语法使用详解
39 0
|
5月前
|
缓存
Thymeleaf参考手册
Thymeleaf参考手册
|
8月前
|
XML 移动开发 JSON
Thymeleaf简介-HelloWorld基本语法:
Thymeleaf简介-HelloWorld基本语法:
53 0
|
9月前
|
前端开发 Java
thymeleaf 入门篇(一),简单语法介绍
thymeleaf 入门篇,基本语法介绍
141 0
|
开发框架 前端开发 JavaScript
FreeMarker的基本语法
FreeMarker的基本语法
150 0
FreeMarker的基本语法
|
前端开发
Thymeleaf 语法学习
Thymeleaf 语法学习,要学习语法,还是参考官网文档最为准确,我们找到对应的版本看一下;
Thymeleaf 语法学习
|
Java 程序员 Maven
模板引擎:第二章:Thymeleaf
模板引擎:第二章:Thymeleaf
132 0
模板引擎:第二章:Thymeleaf