使用场景:项目的新开窗口中,为了保持页面样式统一,使用sitemesh将页面结构提取出来,并且不需要单独每个新开窗口都要引入公共的css和js文件
使用方法:1、将sitemesh的包引入到build.gradle中:compile "opensymphony:sitemesh:2.4.2"
2、在webconfig中配置bean:
@Bean
public FilterRegistrationBean siteMeshFilter() {
Filter filter = new SiteMeshFilter();
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(filter);
registrationBean.setUrlPatterns(Arrays.asList("/*"));
return registrationBean;
}
3、创建公共的页面结构
4、在web-inf目录下,创建decorators.xml文件,里面配置需要被装饰的页面路径
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/views">
<!-- 需要打开新窗口的页面 -->
<decorator name="window" page="decorators/newWindow.jsp">
<pattern>/vehicle/create</pattern>
</decorator>
</decorators>