SpringBoot中Thymeleaf基本语法

时间:2019-08-21 23:24:27   收藏:0   阅读:599

SpringBoot中Thymeleaf基本语法

本节咱们介绍Thymeleaf的基本语法


学习视频: http://www.itlaoqi.com/chapter/1688.html

源码地址: QQ群 814077650 , 群共享中自助下载

老齐的官网: itlaoqi.com (更多干货就在其中)


页面中显示Model中的变量

<td th:text="${emp.empno}"></td>
<td>[[${stat.index}]]</td>
两者等价

分支与判断

Thymeleaf使用下面三种方式实现分支与判断

th:text="${emp.comm }!= null? ${emp.comm} : 'N/A'"
<a href="#" th:if="${size>0}">
<a href="#" th:unless="${size>0}">
<td th:switch="${emp.dname}">
    <span th:case="RESEARCH">研发部</span>
    <span th:case="SALES">销售部</span>
    <span th:case="ACCOUNTING">会计部</span>
    <span th:case="*">其他部门</span>
    <!--在thymeleaf中只有th:if / th:unless 没有th:elseif -->
</td>

迭代遍历

<tr th:each="emp,stat:${emps}" >
    <td>[[${stat.index+1}]]</td>
    <td>[[${#dates.format(emp.hiredate , 'yyyy年MM月dd日')}]]</td>
</tr>

stat.index代表索引值,默认从0开始

时间、数字进行格式化

thymeleaf提供了一些列内置对象

<td th:text="${emp.comm!=null}?${#numbers.formatCurrency(emp.comm)}:'N/A'"></td>
<td>[[${#dates.format(emp.hiredate , 'yyyy年MM月dd日')}]]</td>
<td>[[${#strings.toLowerCase(emp.ename)}]]</td>

获取请求参数

原文:https://www.cnblogs.com/itlaoqi/p/11391787.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!