SpringMVC配置多视图配置的优先级别问题

在使用springmvc集成jsp和freemarker时,我们要在spriingmvc的配置文件中同时配置sp的解析器和freemarker的解析器,同时解析器order属性(order越小,优先级别越高),指定视图的解析优先级,于是配置如下:

 

<beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xmlns:context="http://www.springframework.org/schema/context" 
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 
 
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="com.lyl.controller"></context:component-scan>
   
   
    <!-- jsp视图解析器 -->
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
        <property name="order" value="1"></property>
        <property name="cache" value="false"></property>
    </bean>       
   
    <!-- FreeMarker环境配置 -->
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <!-- freemarker模板位置 -->
        <property name="templateLoaderPath" value="/WEB-INF/freemarker/"/>
    </bean>
  
   
    <!-- FreeMarker视图解析 -->
    <bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="cache" value="true"/>
        <property name="prefix" value="/"/>
        <property name="suffix" value=".xhtml"/>
        <property name="order" value="0"></property>
    </bean>
   
</beans> 

 

 

红色字体部分,需要注意,一定要设置freemarker的优先级别高于jsp,这样当找不到相应的freemarker页面时,还会继续找jsp页面,否则,当jsp页面不存在,会报404错误!

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值