1.导入pom依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.配置模板引擎的参数
配置缓存未false
Thymeleaf默认会开启页面缓存,提高页面并发能力,但会导致我们修改页面不会立即被展现,所以关闭缓存会更快显示
thymeleaf:
cache: false
mode: HTML
配置视图的前后缀
mvc:
view:
prefix: /templates
3.创建Thymeleaf模板页面
》在resource文件夹下面建一个templates文件夹,用于存放模板页面
》创建模板页面xx.html
》引入命名空间
<html xmlns:th="http://www.thymeleaf.org">
》现在就可以通过controller请求该页面,动态渲染页面数据了。
4.关于Thymeleafy页面引入外部css,jss的问题
正确的打开姿势
<link th:href="@{css/bootstrap.min.css}" rel="stylesheet">
<script th:src="@{js/jquery-1.10.0.js}"></script>
静态资源一般放在resources/static包下,通过@{ }拿到static文件下的对应资源。