1. 程式人生 > >徹底解決Spring Boot1.5.X版本不支援Velocity模板引擎的方法

徹底解決Spring Boot1.5.X版本不支援Velocity模板引擎的方法

最近在做關於Spring Boot開發的專案,因為專案中要用到Velocity的模板引擎,而現在新版本在官網上已經不支援Velocity了。

不能加入velocity相關的依賴

下載的是:

下下來之後是這樣一個東西:

然後在Idea中匯入jar包,點選file中的project structure:

然後選擇modules中的dependencies,點選那個+號,找到你剛剛下載好的檔案,就可以匯入外部的jar包了。

因為當初官網初始化Spring的時候沒有選擇模板引擎,現在需要自己手動新增:

找到pom.xml檔案,在<dependencies></dependencies>中間加入:

文字格式:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-velocity</artifactId>
</dependency>

<dependency>
   <groupId>org.apache.velocity</groupId>
   <artifactId>velocity-engine-core</artifactId>
   <version>2.0</version>
</dependency>

<dependency>
   <groupId>org.apache.velocity</groupId>
   <artifactId>velocity-tools</artifactId>
   <version>2.0</version>
</dependency>

然後手動將Spring Boot的版本改小。原來是Spring Boot 1.5.15,現在改成1.4.0,這個版本支援Velocity。

改好後,儲存,執行,如果你在執行之後能看到這樣的一行,說明你已經成功的匯入了velocity的依賴

然後就可以在網頁中開啟自己寫的.vm模板檔案了。