springmvc多视图映射

springmvc同时映射jsp,和velocity,在controller中只需返回一个view的名字,然后先去velocity中找,找到就返回,找不到就去jsp中找。找的先后顺序是通过order配置的。


dispatcher-servlet.xml的配置如下:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <!-- 增加对annotation的支持 -->
    <mvc:annotation-driven></mvc:annotation-driven>


    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/productList/fuzzySearch/*/*.html" />
            <bean id="testInterceptor" class="com.web.frontpage.mvc.intercrptor.TestInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>


    <!-- 自动扫描controll -->
    <context:component-scan base-package="com.web.frontpage.controller"></context:component-scan>


    <!-- jsp视图映射 -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/page/"></property>
        <property name="suffix" value=".jsp"></property>
        <property name="order" value="1"></property>
    </bean>


    <!-- velocity配置 -->


    <!-- velocity的配置 -->
    <bean id="velocityConfigure"
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="configLocation" value="classpath:velocity/velocity.properties"></property>
        <property name="resourceLoaderPath" value="/WEB-INF/vm/"></property>
        <property name="velocityProperties">
        <props>
        <prop key="input.encoding">UTF-8</prop>
        <prop key="output.encoding">UTF-8></prop>
        </props>
        </property>
    </bean>

    <!--spring 对velocity文件的映射 -->
    <bean id="velocityViewResolver"
        class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="suffix" value=".vm"></property>
        <property name="exposeRequestAttributes" value="true"></property>
        <property name="exposeSessionAttributes" value="true"></property>
        <property name="contentType" value="text/html;charset=UTF-8"></property>
        <property name="order" value="0"></property>
    </bean>



    <!-- 增加对json的支持 -->
    <bean id="convereJson"
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>

    <bean id="anotationAdapter"
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="convereJson" />
            </list>
        </property>
    </bean>

    <!-- 增加对上传的支持 -->
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="1024000"></property>
        <property name="defaultEncoding" value="utf-8"></property>
    </bean>

</beans>




velocity.properties内容如下:

resource.loader=webapp
webapp.resource.loader.class=org.apache.velocity.tools.view.servlet.WebappLoader
webapp.resource.loader.path=/WEB-INF/vm/
input.encoding=UTF-8
output.encoding=UTF-8


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sust2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值