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>

  

 

你可能感兴趣的:(springMVC,整合,veolcity)