thymeleaf概述
1、概述
Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎
2、原理
3、引入themeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐thymeleaf</artifactId>
</dependency>
4、thymeleaf
SpringBoot中,只要我们把html页面放在classpath:/templates/,themeleaf就能自动渲染
1、导入thymeleaf的语法
<html lang="en" xmlns:th="http://www.thymeleaf.org">
2、使用thymeleaf的语法
1、th:text;改变当前元素里面的文本内容;
th:任意html属性;来替换原生属性的值
2、thymeleaf表达式
:
获
取
变
量
值
;
O
N
G
L
;
1
、
获
取
对
象
的
属
性
、
调
用
方
法
2
、
使
用
内
置
的
基
本
对
象
3
、
内
置
的
一
些
工
具
对
象
∗
:
选
择
表
达
式
;
和
{}:获取变量值;ONGL; 1、获取对象的属性、调用方法 2、使用内置的基本对象 3、内置的一些工具对象 *{}:选择表达式;和
:获取变量值;ONGL;1、获取对象的属性、调用方法2、使用内置的基本对象3、内置的一些工具对象∗:选择表达式;和{}在功能上是一样的;
#{}:获取国际化内容
@{}:定义url
例子:@{/order/process(execId=${execId},execType=‘FAST’)} ~{}:片段引用表达式
3、thyemeleaf使用补充: 日志格式化:th:text="${#dates.format(emp.birth,‘yyyy-MM-dd HH:mm’)}"