SpringBoot thymeleaf使用方法,thymeleaf模板迭代

SpringBoot thymeleaf使用方法,thymeleaf模板迭代

SpringBoot thymeleaf 循环List、Map

================================

©Copyright 蕃薯耀 2018年3月27日

http://www.cnblogs.com/fanshuyao/

附件下载见:http://fanshuyao.iteye.com/blog/2414521

一、thymeleaf模板基本显示:

Html代码  收藏代码
  1. <div th>thymeleaf模板语言测试</div>  
  2. <div>您好,   
  3.   <span class="cc" id="aaa" th:text="${myname}" th:id="${id}"></span>  
  4. </div>  
  5. <div class="cc" id="bbb" th:text="'姓名:'+${myname}" th:id="'id_'+${id}"></div>  

二、迭代List

Html代码  收藏代码
  1. <div>==========List迭代==============</div>  
  2. <ul>  
  3. <li th:each="data : ${list}" th:text="${data}"></li>  
  4. </ul>  

三、students集合对象迭代

Html代码  收藏代码
  1. <div>==========students迭代==============</div>  
  2. <ul>  
  3.   <li  th:each="student : ${students}" th:text="'姓名:' + ${student.name} + ',年龄:' + ${student.age}"></li>  
  4. </ul>  

四、students集合对象迭代第二种方式,使用双竖线:|xxxx|

Html代码  收藏代码
  1. <div>==========students迭代2,使用双竖线:|xxxx|==============</div>  
  2. <ul>  
  3.     <li  th:each="student : ${students}" th:text="|姓名:${student.name} ,年龄:  ${student.age}|"></li>  
  4. </ul>  

五、students集合对象迭代第三种方式,使用中括号:[[]]或[()],这2个的区别在对于特殊字符是否转义

Html代码  收藏代码
  1. <div>==========students迭代3,使用中括号:[[]]或[()]==============</div>  
  2. <ul>  
  3.     <li  th:each="student : ${students}" >姓名:[[${student.name}]],年龄:[(${student.age})]</li>  
  4. </ul>  

六、Map迭代

Html代码  收藏代码
  1. <div>==========Map迭代==============</div>  
  2. <ul>  
  3.     <li  th:each="m : ${map}" >key:[[${m.key}]],值:[(${m.value})]</li>  
  4. </ul>  

七、模板语言基本用法:(附件在Pdf文档:usingthymeleaf.pdf)

1、基本语法:



 

2、对应的属性:



 

================================

©Copyright 蕃薯耀 2018年3月27日

http://www.cnblogs.com/fanshuyao/

原文地址:https://www.cnblogs.com/fanshuyao/p/8655935.html