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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值