2018年02月24日 14:32:31

阅读数:1382

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:布尔值,当前循环是否是最后一个

  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>

thymeleaf 之 th:each迭代循环对象集合的更多相关文章

  1. 再谈使用Emit把Datatable转换为对象集合(List<T>)

    一.前因和存在的问题 前面我写了一篇<使用Emit把Datatable转换为对象集合(List<T>)>的博文,其实起源于我自己编写的一个orm工具(见前面几篇博文有介绍),里 ...

  2. 使用Emit把Datatable转换为对象集合(List<T>)

    Emit生成动态方法部分摘自网上,但是经过修改,加入了对委托的缓存以及类结构的调整,使之调用更简洁方便.大致的思路是:要实现转换datatable到某个指定对象的集合,本质是实现转换一个datarow ...

  3. C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。

    C#中对象,字符串,dataTable.DataReader.DataSet,对象集合转换成Json字符串方法. public class ConvertJson { #region 私有方法 /// ...

  4. 利用反射与dom4j读取javabean生成对应XML和读取XML得到对应的javabean对象集合

    转自:http://blog.csdn.net/zhao19861029/article/details/8473245 首先实现生成对应的JAVAbean的XML文件方法 /** * DMO4J写入 ...

  5. JSON转换类(二)--List转换成Json、对象集合转换Json等

    #region List转换成Json /// <summary> /// List转换成Json /// </summary> public static string Li ...

  6. JSon_零基础_005_将po(bean)对象集合List转换为JSon格式的对象字符串,返回给界面

    将po(bean)对象集合List转换为JSon格式的对象字符串,返回给界面 导入jar包: 编写:po(bean)代码: package com.west.webcourse.po; /** * 第 ...

  7. List转换成Json、对象集合转换Json等

    #region List转换成Json /// <summary> /// List转换成Json /// </summary> public static string Li ...

  8. [Json] C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json (转载)

    点击下载 ConvertJson.rar 本类实现了 C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json|等功能大家先预 ...

  9. C#高级知识点概要(3) - 特性、自动属性、对象集合初始化器、扩展方法、Lambda表达式和Linq查询

    1.特性(Attributes) 特性(Attributes),MSDN的定义是:公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法 ...

随机推荐

  1. 百度地图API 显示区域边界及地名定位

    百度地图API 显示区域边界及地名定位 这个定位一共用了两个方法组成 一个是定位绘制区域边界线,另一个是地名定位 原理: 当用户输入省.市.县.区这种大地名时,我们要定位用户输入的这个位置,并显示轮廓 ...

  2. linux 前端部署

    linux.conf user root; worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice ...

  3. wpf中把按钮变成圆角

      <Button x:Name="btn" Content="改变" Width="100" Height="50&quo ...

  4. hadoo异常——org.apache.hadoop.security.UserGroupInformation: PriviledgedActionException

    2013-08-20 10:36:17,728 INFO org.apache.hadoop.http.HttpServer: listener.getLocalPort() returned 500 ...

  5. Leetcode 12

    //日积月累,水滴石穿class Solution { public: string longestCommonPrefix(vector<string>& strs) { if ...

  6. JS BOM操作

    Bom:浏览器对象模型(Browser Object Model,简称 BOM)提供了独立于内容而与浏览器窗口进行交互的对象.描述了与浏览器进行交互的方法和接口,可以对浏览器窗口进行访问和操作 (1) ...

  7. 011PHP文件处理——文件处理 文件内容分页操作类

    <?php /** * 文件内容分页操作类: */ //访问地址:http://basicphp.com/006file/011.php?&page=1 class StrPage { ...

  8. 利用Sonar定制自定义JS扫描规则(三)——SSLR JavaScript Toolkit 使用说明

    在上一篇blog中讲了在sonar中如何新增自定义的JS规则,这里面比较难的地方是XPath语句的编写,而要编写正确的XPath语句,首先要拿到语法的AST,下面我们就来介绍如何使用SSLR Java ...

  9. 关于面向对象和String类型的 09,10

    package test.面试题; public class Test9 { public static void main(String[] args){ Outer.Inner in=new Ou ...

  10. New Concept English Two 5

    $课文9 冷遇 83. On Wednesday evening, we went to the Town Hall. 星期三的晚上,我们去了市政厅. 84. It was the last day ...