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>状态变量:indexth>  
  9.                 <th>状态变量:countth>  
  10.                 <th>状态变量:sizeth>  
  11.                 <th>状态变量:current.userNameth>  
  12.                 <th>状态变量:eventh>  
  13.                 <th>状态变量:oddth>  
  14.                 <th>状态变量:firstth>  
  15.                 <th>状态变量:lastth>  
  16.               tr>  
  17.               <tr  th:each="user,userStat : ${list}">  
  18.                 <td th:text="${user.userName}">Onionstd>  
  19.                 <td th:text="${user.email}">[email protected]td>  
  20.                 <td th:text="${user.isAdmin}">yestd>  
  21.                  <th th:text="${userStat.index}">状态变量:indexth>  
  22.                 <th th:text="${userStat.count}">状态变量:countth>  
  23.                 <th th:text="${userStat.size}">状态变量:sizeth>  
  24.                 <th th:text="${userStat.current.userName}">状态变量:currentth>  
  25.                 <th th:text="${userStat.even}">状态变量:even****th>  
  26.                 <th th:text="${userStat.odd}">状态变量:oddth>  
  27.                 <th th:text="${userStat.first}">状态变量:firstth>  
  28.                 <th th:text="${userStat.last}">状态变量:lastth>  
  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>  

转载于:https://www.cnblogs.com/pejsidney/p/9071102.html

你可能感兴趣的:(thymeleaf 之 th:each迭代循环对象集合)