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>

  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值