天天看点

Spring boot 集成 thymeleaf

只需要一个依赖,非常简单:

如果没有使用 spring-boot-starter-parent 还需要制定版本号: <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>

添加依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>

通过这个类可以看到Spring-thymeleaf的默认配置项 org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties

//默认会到 templates加载模板 public static final String DEFAULT_PREFIX = "classpath:/templates/"; //默认后缀为html public static final String DEFAULT_SUFFIX = ".html"

ThymeleafProperties类上面有这么一句: @ConfigurationProperties( prefix = "spring.thymeleaf" ) 所以如果需要修改前后缀可以在配置文件中配置: spring.thymeleaf.prefix = classpath:/templates/ spring.thymeleaf.suffix = .html

;

继续阅读