0

我正在尝试将 Tiles 2 与 Spring MVC 集成,但我得到的是一个特定的 jsp,而不是 Tiles View。例如,如果 request="about.htm" 那么我得到 about.jsp ,它保存在 /jsp/about.jsp 。就好像视图正在通过 UrlBasedViewResolver 解析一样。我的 Spring-servlet.xml 是

<mvc:annotation-driven />
    <context:component-scan base-package="com.spring.controller" />

    <mvc:resources mapping="/resources*" location="resources/"/>



    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
    </bean>

    <bean id="TilesViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="views" />
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" p:definitions="/WEB-INF/tiles-defs.xml" />

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="dataSource"/>
    </bean>

    <bean id="loginDao" class="com.spring.dao.impl.LoginDaoImpl">
        <property name="jdbcTemplate" ref="jdbcTemplate"/>
    </bean>

保存在类下的views.properties 是

welcome.(class)=org.springframework.web.servlet.view.tiles2.TilesView
welcome.url=welcome

friends.(class)=org.springframework.web.servlet.view.tiles2.TilesView
friends.url=friends

office.(class)=org.springframework.web.servlet.view.tiles2.TilesView
office.url=office

about.(class)=org.springframework.web.servlet.view.JstlView
about.url=/jsp/about.jsp

瓷砖-defs.xml 是

<tiles-definitions>

<definition name="baseLayout" template="/WEB-INF/tiles/baseLayout.jsp">
  <put-attribute name="title"  value="Template"/>
  <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/>
  <put-attribute name="menu"   value="/WEB-INF/tiles/menu.jsp"/>
  <put-attribute name="body"   value="/WEB-INF/tiles/body.jsp"/>
  <put-attribute name="footer"   value="/WEB-INF/tiles/footer.jsp"/>
</definition>

<definition name="welcome" extends="baseLayout">
  <put-attribute name="title"  value="Welcome"/>
  <put-attribute name="body"   value="/jsp/welcome.jsp"/>      
</definition>

<definition name="friends" extends="baseLayout">
  <put-attribute name="title"  value="Friends"/>
  <put-attribute name="body"   value="/jsp/friends.jsp"/>      
</definition>

<definition name="office" extends="baseLayout">
  <put-attribute name="title"  value="Office"/>
  <put-attribute name="body"   value="/jsp/office.jsp"/>      
</definition>

</tiles-definitions>

请指导。

4

1 回答 1

1

视图解析器顺序可能有问题,如果您想优先考虑平铺视图解析器,请为视图解析器添加 order 属性

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
    <property name="order" value="2"/>
</bean>
<bean id="TilesViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="views" p:order="1"/>
于 2013-03-28T15:58:54.047 回答