`
longying2008
  • 浏览: 300279 次
社区版块
存档分类
最新评论

SpringMVC与Velocity整合

阅读更多

1.依赖的Jar包

  (1). velocity-1.x.x.jar

  (2). commons-collections.jar

  (3). spring的基础Jar包

    spring-aop

    spring-web

    spring-context

    spring-context-support

    spring-beans

    spring-core

    spring-webmvc

  (4). servlet-api

2.在'*-servlet.xml'中配置beans

<context:component-scan base-package="com.wgc.test"></context:component-scan>
<mvc:annotation-driven/>
<!-- 
This bean sets up the Velocity environment for us based on a root path for templates.
Optionally, a properties file can be specified for more control over the Velocity
environment, but the defaults are pretty sane for file based template loading.
-->
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
	<property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
</bean>
<!--
View resolvers can also be configured with ResourceBundles or XML files. If you need
different view resolving based on Locale, you have to use the resource bundle resolver.
-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
    <property name="cache" value="true"/>
    <property name="prefix" value=""/>
    <property name="suffix" value=".vm"/>
</bean> 

3.创建视图模板

把视图模板存放在上面配置的路径中(/WEB-INF/velocity/)

4.更为详细的配置velocity.properties

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
	<!-- 指定velocity.properties配置文件的路径 -->
	<property name="configLocation" value="/WEB-INF/velocity.properties"/>
</bean>

  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics