Thymeleaf 是一款用于渲染 XML/XHTML/HTML5 内容的模板引擎。类似 JSP,Velocity,FreeMaker 等,它也可以轻易的与 Spring MVC 等 Web 框架进行集成作为 Web 应用的模板引擎。与其它模板引擎相比,Thymeleaf 最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个 Web 应用。
1、导入Thymeleaf依赖包
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
2、Html文件中需要加入命名空间
<html xmlns:th="http://www.thymeleaf.org">
3、Html中所有链接都要修改为thymeleaf语法
修改前
<link href="dashboard.css" rel="stylesheet">
修改后
<link th:href="@{/css/dashboard.css}" rel="stylesheet">