这一篇文章来介绍下如何通过官方支持的Thymeleaf模板渲染Web页面。
Thyemeleaf Logo
添加Maven依赖
在pom.xml文件中添加spring-boot-starter-thymeleaf依赖。
SpringBoot Thymeleaf Starter
Thymeleaf配置
默认情况下,SpringBoot会从 src/main/resources/templates 文件夹目录中找模板文件。可以通过在application.properties文件中添加如下配置进行自定义属性。
SpringBoot Thymeleaf Configuration
配置定义了从 src/main/resources/templates/thymeleaf 文件夹下面中后缀为.html的模板文件。
Thymeleaf模板文件
我们在 src/main/resources/templates/thymeleaf 文件夹新建index.html文件。