天天看點

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

;

繼續閱讀