在webmvc.xml中映射InternalResourceViewResolver和TilesViewResolver的正确方法是什么

时间:2017-06-26 08:55:29

标签: spring spring-mvc

我必须整合两个项目。 一个项目包含所有jsp文件,另一个项目包含jspx。

以下是webmvc配置文件中的文件条目。

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="suffix">
        <value>.jsp</value>
    </property>
     <property name="order" value="1"/>     
</bean>

<bean id="viewResolver" 
  class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
    <property name="viewClass" 
     value="org.springframework.web.servlet.view.tiles3.TilesView"/>
    <property name="viewNames">
        <list>
            <value>list.jspx</value>
            <value>menu.jspx</value>
            <value>show.jspx</value>
            <value>create.jspx</value>
            <value>update.jspx</value>
         </list>
    </property>
    <property name="order" value="0"/>
</bean>


<!-- Tiles configuration -->
<bean id="tilesConfigurer" 
 class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles/tiles-definitions.xml</value>
            <value>/WEB-INF/admin/layouts/layouts.xml</value>
            <value>/WEB-INF/admin/views/**/views.xml</value>
        </list>
    </property>
</bean>

我得到的错误是找不到.jspx文件。

url&#34; settings / surveyDefinitions / list&#34;

14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'settings/surveyDefinitions/list'
14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'settings/surveyDefinitions/list'; URL [settings/surveyDefinitions/list.jsp]] in DispatcherServlet with name 'hifi-web-dispatcher'
14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.web.servlet.view.JstlView - Added model object 'modelAndView' of type [org.springframework.web.servlet.ModelAndView] to request in view with name 'settings/surveyDefinitions/list'
14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.web.servlet.view.JstlView - Added model object 'org.springframework.validation.BindingResult.modelAndView' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'settings/surveyDefinitions/list'
14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.web.servlet.view.JstlView - Added model object 'surveyDefinitions' of type [java.util.LinkedHashSet] to request in view with name 'settings/surveyDefinitions/list'
14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.web.servlet.view.JstlView - Added model object 'maxPages' of type [java.lang.Integer] to request in view with name 'settings/surveyDefinitions/list'
14:12:26.888 [http-nio-8080-exec-6] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [settings/surveyDefinitions/list.jsp] in InternalResourceView 'settings/surveyDefinitions/list'

它取settings/surveyDefinitions/list.jsp而非list.jspx。 任何想法或建议。

1 个答案:

答案 0 :(得分:0)

我认为我做错了,我做的是,

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
    <property name="order" value="0"/>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="suffix" value=".jsp" />
    <property name="order" value="1"/>
</bean>

    <!-- Tiles configuration -->
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles/tiles-definitions.xml</value>
                <value>/WEB-INF/admin/layouts/layouts.xml</value>
                <value>/WEB-INF/admin/views/**/views.xml</value>
            </list>
        </property>
    </bean>