一、springboot配置thymeleaf
1.1 springboot版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
1.2 场景启动器
这里不需要配置spring-boot-starter-thymeleaf的版本,使用springboot默认的就可以
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
1.3 thymeleaf配置
#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false #开发时关闭缓存
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.mode=HTML5
最后两项被注释,因为启动这两项会报错
- #spring.thymeleaf.encoding=UTF-8
启动时报错
Description:
Binding to target org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties@17271176 failed:
Property: spring.thymeleaf.encoding
Value: UTF-8
Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.nio.charset.Charset' for property 'encoding'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.nio.charset.Charset]
Action:
Update your application's configuration
- #spring.thymeleaf.mode=HTML5
运行时报错
org.thymeleaf.exceptions.TemplateInputException: Template mode "HTML5 " has not been configured
二、文档介绍
2.1 thymeleaf官网使用
点击跳转获取thymeleaf
获取配置