引入依赖
在pom.xml中引入模板
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在 application.properties文件中添加Thymeleaf配置
- 模板的模式,支持HTML,XML,TEXT,JAVASCRIPT等
spring.thymeleaf.mode=HTML5 - 编码,可不用配置
spring.thymeleaf.encoding=UTF-8 - 内容类别,可不用配置
spring.thymeleaf.content-type=text/html - 开发配置为false,避免修改模板还要重启服务器
spring.thymeleaf.cache=false - 配置模板路径,默认是templates,可以不用配置
spring.thymeleaf.prefix=classpath:/templates/
注意:Thymeleaf模板引擎默认会读取springboot项目资源文件夹的resource下的templates目录,这个目录是用来存放HTML文件的.如果我们添加了Thymeleaf依赖,而没有进行任何配置,或者添加默认目录,启动时就会报错.
image.png
image.png












网友评论