Spring 3 MVC多视图解析器(Jsp和Velocity) [英] Spring 3 MVC Multiple view resolvers(Jsp and Velocity)

查看:116
本文介绍了Spring 3 MVC多视图解析器(Jsp和Velocity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些业务/技术限制,我们应该使用spring3 MVC多视图解析器( JSP和Velocity ).我试图对此进行网上搜索,但找不到完美的解决方案.可能是其他人也经历过相同的情况.因此,请您告诉我,是否可以在SPring3 MVC应用程序中同时使用 JSP和Velocity作为vew解析器?

感谢所有帮助.

解决方案

Spring支持多个视图解析器.您可以通过在应用程序上下文中添加多个解析器来链接视图解析器,并使用order属性指定排序.

您可以像使用链式连接这些jsp和速度-

    <bean id="viewResolver" 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="2" />
    </bean>

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
</bean>

<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"/>
  <property name="order" value="1" />
</bean>

了解有关视图链接的更多信息此处

Because of some business/technical constraints we should use spring3 MVC multiple view resolvers(JSP and Velocity). I tried to search on net on this but i couldn't find perfect solution. May be someone else had experienced the same scenario. So Could you please let me know is it possible to use both JSP and Velocity as vew resolvers in the SPring3 MVC application

All help is appreciated.

解决方案

Spring support multiple view resolvers. You chain view resolvers by adding more than one resolver to your application context and use the order property to specify ordering.

you can use chain these jsp and velocity like -

    <bean id="viewResolver" 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="2" />
    </bean>

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
</bean>

<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"/>
  <property name="order" value="1" />
</bean>

Find out more about view chaining here

这篇关于Spring 3 MVC多视图解析器(Jsp和Velocity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆