码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc 配置多视图,返回jsp,velocity,freeMarker,tiles(模板)等等

时间:2016-07-07 00:42:01      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

springmvc-servlet.xml配置

<!--  Velocity -->
    <bean id="velocityViewResolver" class = "org.springframework.web.servlet.view.velocity.VelocityViewResolver">
         <property name="order" value="0" />
         <property name="contentType" value="text/html;charset=UTF-8" />
         <property name="requestContextAttribute" value="req"/>
    </bean>

    <!-- Velocity -->     
    <bean id="velocityConfig" class = "org.springframework.web.servlet.view.velocity.VelocityConfigurer">
         <property name="configLocation" value="/WEB-INF/velocity.properties"/>
         <property name="resourceLoaderPath" value="/" />
    </bean>
    
    <!--  FreeMarker -->
    <bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">  
        <property name="order" value="0" />
        <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>  
    </bean> 
    
    
    <!-- FreeMarker-->     
    <bean id="freemarkerConfig"  class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">  
       <property name="configLocation" value="/WEB-INF/freemarker.properties"/>
        <property name="templateLoaderPath" value="/WEB-INF/ftl/"/>  
         <property name="freemarkerVariables">
             <map>
                <entry key="xml_escape" value-ref="fmXmlEscape"/>
            </map>
         </property>
    </bean>   
    
    <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
  
  
     <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">     <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></property>     <property name="order" value="1" />   </bean>   <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">     <property name="definitions">         <list>           <value>classpath:layout.xml</value>         </list>     </property>   </bean> <!-- 定义JSP文件的位置 -->   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">     <property name="prefix" value="/WEB-INF/pages/"/>     <property name="suffix" value=".jsp"/>     <property name="order" value="1" />   </bean>

注意:关键点 <property name="order" value="1" />配置 0,1,2,3,4,5,6......首先从0开始解析,依次往下,jsp的一定要放到最后,不然找到返回页面直接返回到404页面

  了,不会去其他页面匹配了,或者吧jsp的order设置到最高,这是个坑,或者自己写解析器进行解析。就是这么easy

springmvc 配置多视图,返回jsp,velocity,freeMarker,tiles(模板)等等

标签:

原文地址:http://www.cnblogs.com/ijuzi/p/5648477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!