springboot-2.1.8 如何整合velocity
时间: 2024-05-09 17:17:40 浏览: 167
可以通过添加velocity-starter依赖来整合Velocity,具体步骤如下:
1. 在pom.xml文件中添加以下依赖:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
```
2. 在application.properties文件中添加以下配置:
```
spring.velocity.cache=false # 禁用Velocity缓存
spring.velocity.charset=UTF-8 # 设置Velocity编码为UTF-8
spring.velocity.allow-request-override=true # 允许请求覆盖
spring.velocity.prefer-file-system-access=false # 禁用文件系统访问
spring.velocity.suffix=.vm # 设置Velocity视图后缀为.vm
spring.velocity.prefix=classpath:/templates/ # 设置Velocity视图文件位置
```
3. 创建Velocity模板文件,存放在/templates目录下。
4. 在Controller类中使用@Rendrering注解返回Velocity模板名称。
例如:
```
@Controller
public class HomeController {
@RequestMapping("/")
public String home() {
return "index";
}
}
```
这将返回/templates目录下的index.vm模板文件。
阅读全文
相关推荐







