码迷,mamicode.com
首页 > 编程语言 > 详细

Spring整合Velocity模版引擎

时间:2014-10-21 00:49:48      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   sp   文件   div   

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结尾。

Spring整合Velocity模版引擎

标签:style   blog   color   io   os   ar   sp   文件   div   

原文地址:http://www.cnblogs.com/liuriqi/p/4039201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!