zoukankan      html  css  js  c++  java
  • Spring整合Velocity模版引擎

    1. 首先通过pom.xml自动加载velocity扩展包到工程:

    1 <dependency>
    2     <groupId>velocity</groupId>
    3     <artifactId>velocity</artifactId>
    4     <version>1.5</version>
    5 </dependency>

    2. 然后在自动装载bean的xml里边添加如下配置:

     1 <bean id="velocityConfig"
     2     class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
     3     <property name="resourceLoaderPath" value="/WEB-INF/views/" />
     4     <property name="velocityPropertiesMap">
     5         <props>
     6             <prop key="input.encoding">utf-8</prop>
     7             <prop key="output.encoding">utf-8</prop>
     8         </props>
     9     </property>
    10 </bean>
    11 <bean id="viewResolver"
    12     class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
    13     <property name="cache" value="true" />
    14     <property name="exposeSpringMacroHelpers" value="true" />
    15     <property name="suffix" value=".vm" />
    16     <property name="contentType" value="text/html;charset=UTF-8" />
    17 </bean>

    通过如上配置,Spring工程就支持Velocity模版引擎了,模版文件位于:/WEB-INF/views/目录下,指定输入和输出编码为UTF-8编码,同时指定了模版的后缀名称为.vm结尾。

  • 相关阅读:
    poj 1035 字符串匹配
    拓扑排序的小总结
    POJ1018
    POJ1328详细题解
    POJ1159题解报告
    POJ1088 (滑雪)
    树状树组区间修改,单点修改模板
    spfa模板
    树状树组离散化求逆序对模板
    POJ3723(最小生成树,负权)
  • 原文地址:https://www.cnblogs.com/liuriqi/p/4039201.html
Copyright © 2011-2022 走看看