1. 程式人生 > 程式設計 >springboot2.1.7整合thymeleaf程式碼例項

springboot2.1.7整合thymeleaf程式碼例項

這篇文章主要介紹了springboot2.1.7整合thymeleaf程式碼例項,文中通過示例程式碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

1.在pom裡面新增thymeleaf依賴

<!--thymeleaf-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- 使用springboot的thymeleaf模板時預設會對HTML進行嚴格的檢查,導致當你的標籤沒有閉合時就會通不過,nekohtml這個依賴可以解決這一問題-->
    <dependency>
      <groupId>nekohtml</groupId>
      <artifactId>nekohtml</artifactId>
      <version>${nekohtml.version}</version>
    </dependency>

2.新增application.properties配置

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。