1.thymeleaf
spring boot 推荐的模板引擎是thymeleaf。spring boot 的自动配置已经默认配置好了themleaf,只要导入themleaf的Starter就可以了。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
为了使用themleaf的高级特性,建议将themleaf版本切换至3.0以上
<properties> <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
themleaf 可以用th:开头的所有标签去替换原生html的相应标签,主要的语法有以下几个点:
(1)${...} 取变量的值,类似于OGNL
(2)#{...}:获取国际化内容
(3)@{...}:定义URL
(4)~{...}:片段引用表达式
(5)*{...}:选择变量表达式,功能和${}类似
themleaf 同时支持字符串操作,数学计算,比较,条件判断,还内置了很多工具方法,如可以进行日期格式化的方法${#dates.format(date)}
原文:https://www.cnblogs.com/li-zhi-long/p/9493442.html