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

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

SpringBoot thymeleaf 循环List、Map

 

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

©Copyright 蕃薯耀 2018年3月26日

http://fanshuyao.iteye.com/

 

一、thymeleaf模板基本显示:

<div th>thymeleaf模板语言测试</div>
<div>您好, 
  <span class="cc" id="aaa" th:text="${myname}" th:id="${id}"></span>
</div>
<div class="cc" id="bbb" th:text="'姓名:'+${myname}" th:id="'id_'+${id}"></div>

二、迭代List

<div>==========List迭代==============</div>
<ul>
<li th:each="data : ${list}" th:text="${data}"></li>
</ul>

三、students集合对象迭代

<div>==========students迭代==============</div>
<ul>
  <li  th:each="student : ${students}" th:text="'姓名:' + ${student.name} + ',年龄:' + ${student.age}"></li>
</ul>

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

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

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

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

六、Map迭代

<div>==========Map迭代==============</div>
<ul>
    <li  th:each="m : ${map}" >key:[[${m.key}]],值:[(${m.value})]</li>
</ul>

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

1、基本语法:



 

2、对应的属性:



 

 

 

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

©Copyright 蕃薯耀 2018年3月26日

http://fanshuyao.iteye.com/

猜你喜欢

转载自fanshuyao.iteye.com/blog/2414521