zoukankan      html  css  js  c++  java
  • thymeleaf 之 th:each迭代循环对象集合

    thymeleaf 之 th:each迭代循环对象集合

    th:each属性用于迭代循环,语法:th:each="obj,iterStat:${objList}"

    迭代对象可以是java.util.List,java.util.Map,数组等;

    iterStat称作状态变量,属性有:
        index:当前迭代对象的index(从0开始计算)
        count: 当前迭代对象的index(从1开始计算)
        size:被迭代对象的大小
        current:当前迭代变量
        even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
        first:布尔值,当前循环是否是第一个
        last:布尔值,当前循环是否是最后一个

    [html] view plain copy
     
    1. <ol>  
    2.         <li>List循环:  
    3.             <table border="1">  
    4.               <tr>  
    5.                 <th>用户名</th>  
    6.                 <th>邮箱</th>  
    7.                 <th>管理员</th>  
    8.                 <th>状态变量:index</th>  
    9.                 <th>状态变量:count</th>  
    10.                 <th>状态变量:size</th>  
    11.                 <th>状态变量:current.userName</th>  
    12.                 <th>状态变量:even</th>  
    13.                 <th>状态变量:odd</th>  
    14.                 <th>状态变量:first</th>  
    15.                 <th>状态变量:last</th>  
    16.               </tr>  
    17.               <tr  th:each="user,userStat : ${list}">  
    18.                 <td th:text="${user.userName}">Onions</td>  
    19.                 <td th:text="${user.email}">test@test.com.cn</td>  
    20.                 <td th:text="${user.isAdmin}">yes</td>  
    21.                  <th th:text="${userStat.index}">状态变量:index</th>  
    22.                 <th th:text="${userStat.count}">状态变量:count</th>  
    23.                 <th th:text="${userStat.size}">状态变量:size</th>  
    24.                 <th th:text="${userStat.current.userName}">状态变量:current</th>  
    25.                 <th th:text="${userStat.even}">状态变量:even****</th>  
    26.                 <th th:text="${userStat.odd}">状态变量:odd</th>  
    27.                 <th th:text="${userStat.first}">状态变量:first</th>  
    28.                 <th th:text="${userStat.last}">状态变量:last</th>  
    29.               </tr>  
    30.             </table>  
    31.         </li>  
    32.         <li>Map循环:  
    33.             <div th:each="mapS:${map}">  
    34.             <div th:text="${mapS}"></div>  
    35.             </div>  
    36.         </li>  
    37.         <li>数组循环:  
    38.             <div th:each="arrayS:${arrays}">  
    39.             <div th:text="${arrayS}"></div>  
    40.             </div>  
    41.         </li>  
    42.         </ol>  
  • 相关阅读:
    从源码角度看MySQL memcached plugin——3. containers表的管理
    从源码角度看MySQL memcached plugin——2. 线程模型和连接的状态机
    从源码角度看MySQL memcached plugin——1. 系统结构和引擎初始化
    从源码角度看MySQL memcached plugin——0.大纲
    关注博客
    文摘
    MySQL—FTS实现原理介绍PPT
    GIT情况展示说明
    final发布48小时用户调查报告
    final版本发布评价II
  • 原文地址:https://www.cnblogs.com/pejsidney/p/9071102.html
Copyright © 2011-2022 走看看