我试图在春天配置内部视图解析器和tile。但是,对于我搜索的各种尝试和答案,它仍然无法正常工作。如果我删除内部视图解析器配置,然后瓷砖工作正常。但是,如果我一起配置切片和内部视图解析器并相应地配置切片文件,那么事情根本就不起作用。对此有何解决方案?试图设置顺序,但它根本不起作用。 以下是java中的配置文件。
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.springmvc")
public class AppConfig extends WebMvcConfigurerAdapter{
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
viewResolver.setOrder(1);
return viewResolver;
}
@Bean
public TilesConfigurer tilesConfigurer(){
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setDefinitions(new String[] {"/WEB-INF/views/**/tiles.xml"});
tilesConfigurer.setCheckRefresh(true);
return tilesConfigurer;
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
TilesViewResolver viewResolver = new TilesViewResolver();
viewResolver.setViewClass(TilesView.class);
registry.viewResolver(viewResolver);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
}
Tiles.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<!-- Base Definition -->
<definition name="base-definition"
template="/WEB-INF/views/tiles/layouts/defaultLayout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/views/tiles/template/defaultHeader.jsp" />
<put-attribute name="menu" value="/WEB-INF/views/tiles/template/defaultMenu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/tiles/template/defaultFooter.jsp" />
</definition>
<!-- Home Page -->
<definition name="home" extends="base-definition">
<put-attribute name="title" value="Welcome" />
<put-attribute name="body" value="/WEB-INF/views/pages/home.jsp" />
</definition>
<!-- Product Page -->
<definition name="products" extends="base-definition">
<put-attribute name="title" value="Products" />
<put-attribute name="body" value="/WEB-INF/views/pages/products.jsp" />
</definition>
<!-- Contact-us Page -->
<definition name="contactus" extends="base-definition">
<put-attribute name="title" value="Contact Us" />
<put-attribute name="body" value="/WEB-INF/views/pages/contactus.jsp" />
</definition>
</tiles-definitions>
答案 0 :(得分:0)
在App Config中设置Tiles View Resolver Bean的顺序
viewResolver.setOrder(0);
它应该有效,请注意将内部视图解析器的顺序设置为最高(&#34;最低优先级&#34;)。