牛客网头条咨询项目第三课时遇到问题

由于项目讲解时是16年,前端使用的是velocity模板引擎,在spring boot1.5之后已经遭到启用,而笔者在start.sprintg.io中下载的spring boot版本为2.1.4,因此没有集成velocity相关的依赖,导致很多不兼容问题出现。

项目中写好前端代码是使用velocity语言,因此我们要通过以下方式引入velocity相关的依赖。

1.在pom.xml文件中加入以下代码:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-velocity</artifactId>
   <version>1.1.3.RELEASE</version>
</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>

2.将spring boot的版本改到1.5以下:

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>1.4.0.RELEASE</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>

3.在配置文件中加入velocity配置信息

spring.velocity.suffix=.html
spring.velocity.cache=false
spring.velocity.toolbox-config-location=toolbox.xml

4.在main/resource目录下添加toolbox.xml文件

最终得到如下的网页示意图:

牛客网头条咨询项目第三课时遇到问题