1. 程式人生 > >SpringBoot學習-引入thymeleaf

SpringBoot學習-引入thymeleaf

為什麼要thymeleaf?

SpringBoot不支援jsp,可以引入模板引擎來代替使用
JSP、Velocity、Freemarker、Thymeleaf等都是模板引擎
SpringBoot推薦我們使用Thymeleaf;

怎麼引入?

在官方文件中找到場景啟動器Starters
在這裡插入圖片描述
然後在pom.xml中引進來就可以了

<!--引入thymeleaf-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <
artifactId
>
spring-boot-starter-thymeleaf</artifactId> </dependency>

maven會自動幫我們把jar包導進來,版本不用寫它會自動識別
如果想切換版本:
<properties>標籤中指明想要覆蓋的版本就可以了
比如我想切換為3.0.9.RELEASE這個版本,版本可以去GitHub中看

<properties>
	<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
	<!‐‐
佈局功能的支援程式 thymeleaf3主程式 layout2以上版本 ‐‐>
<!‐‐ thymeleaf2 layout1‐‐> <thymeleaf‐layout‐dialect.version>2.2.2</thymeleaf‐layout‐dialect.version> </properties>