pom.xml
<!-- thymeleaf是spring的默认主题 -->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
-->
<!-- 默认配置下spring boot会从src/main/resources/templates目录中去找模板 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
application.properties
# VELOCITY TEMPLATES (VelocityAutoConfiguration)
spring.velocity.resourceLoaderPath=classpath:/templates/
#spring.velocity.suffix=.html
spring.velocity.suffix=.vm
spring.velocity.toolbox-config-location=toolbox.xml
spring.velocity.charset=UTF-8
spring.velocity.properties.input.encoding=UTF-8
spring.velocity.properties.output.encoding=UTF-8
toolbox.xml
<?xml version="1.0"?>
<toolbox>
<tool>
<key>velocityTool</key>
<scope>application</scope>
<class>cn.no7player.util.VelocityTool</class>
</tool>
</toolbox>
页面调用方式:
<td>$!velocityTool.getFormatTime($dateTime)</td>