【开发笔记】- SSM使用velocity模板语言

1、在pom.xml里添加velocity模板语言支持的依赖

<!-- velocity模板语言支持包 -->
<dependency>
  <groupId>org.apache.velocity</groupId>
   <artifactId>velocity</artifactId>
   <version>1.7</version>
</dependency>
<!-- velocity-tools -->
<dependency>
  <groupId>org.apache.velocity</groupId>
  <artifactId>velocity-tools</artifactId>
  <version>2.0</version>
</dependency>

2、spring-mvc.xml中配置velocity

<!--velocity配置-->
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  <property name="resourceLoaderPath" value="/WEB-INF/views"/>
  <property name="velocityProperties">
  <props>
    <prop key="input.encoding">utf-8</prop>
    <prop key="output.encoding">utf-8</prop>
    <prop key="file.resource.loader.cache">false</prop>
    <prop key="file.resource.loader.modificationCheckInterval">1</prop>
    <prop key="velocimacro.library.autoreload">false</prop>
  </props>
  </property>
</bean>

<!--velocity模板语言-->
<bean class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
  <property name="suffix" value=".vm"/>
  <property name="contentType" value="text/html;charset=utf-8"/>
  <property name="dateToolAttribute" value="date"/><!--日期函数名称-->
</bean>

3、新建页面 .vm 后缀的文件

原文地址:https://www.cnblogs.com/juihai/p/10307780.html