我有 Spring MVC 项目,我想使用 Apache Tiles 在我的应用程序中构建视图。我在我的pom.xml
文件中添加了一些依赖项。我想知道我有太多但我有一些关于缺少类的例外,所以我在一些包中找到了它们并将它们添加到类路径中。
<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
<version>3.2</version>
<classifier>with-deps</classifier>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
这是我ViewResolvers
在 Dispatcher Servlet 上下文中的配置。我想知道如何将它们正确配置在一起。
<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles-definitions.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
<beans:property name="order" value="0" />
</beans:bean>
<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<beans:property name="order" value="1" />
</beans:bean>
我已阅读此问答:如何在 Spring 中使用多个 ViewResolver?但这对我没有帮助。目前,上述配置jsp
视图可以正常工作,但对于我得到的瓷砖地址HTTP Status 404
。
编辑
这是我的控制器。与“家”相关的视图正在工作,但其他视图 - 瓷砖不工作。
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home";
}
@RequestMapping(value = "/pets", method = RequestMethod.GET)
public String pets(Locale locale, Model model) {
return "pets-tiles";
}
@RequestMapping(value = "/dogs", method = RequestMethod.GET)
public String dogs(Locale locale, Model model) {
return "dogs-tiles";
}
@RequestMapping(value = "/cats", method = RequestMethod.GET)
public String cats(Locale locale, Model model) {
return "cats-tiles";
}
这是我的tiles-definitions.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="template-main" template="/WEB-INF/views/layouts/main.jsp">
<put-attribute name="banner-content" value="/WEB-INF/views/sections/banner.jsp" />
<put-attribute name="title-content" value="Pet Type" />
<put-attribute name="primary-content" value="" />
<put-attribute name="footer-content" value="/WEB-INF/views/sections/footer.jsp" />
</definition>
<definition name="template-detail" template="/WEB-INF/views/layouts/detail.jsp">
<put-attribute name="banner-content" value="/WEB-INF/views/sections/banner.jsp" />
<put-attribute name="title-content" value="Pet Type" />
<put-attribute name="subtitle-content" value="" />
<put-attribute name="primary-content" value="" />
<put-attribute name="footer-content" value="/WEB-INF/views/sections/footer.jsp" />
</definition>
<definition name="pet-tiles" extends="template-main">
<put-attribute name="primary-content" value="/WEB-INF/views/contents/pets.jsp" />
</definition>
<definition name="dog-tiles" extends="template-detail">
<put-attribute name="subtitle-content" value="Canines" />
<put-attribute name="primary-content" value="/WEB-INF/views/contents/dogs.jsp" />
</definition>
<definition name="cat-tiles" extends="template-detail">
<put-attribute name="subtitle-content" value="Felines" />
<put-attribute name="primary-content" value="/WEB-INF/views/contents/cats.jsp" />
</definition>
</tiles-definitions>
它们来自本教程: http: //krams915.blogspot.com/2010/12/spring-mvc-3-tiles-2-integration.html但不适用于我。