springboot 整合 sitemesh3 步骤如下:
第一步: 创建WebSiteMeshFilter
类
import org.sitemesh.builder.SiteMeshFilterBuilder;
import org.sitemesh.config.ConfigurableSiteMeshFilter;
import org.sitemesh.content.tagrules.html.DivExtractingTagRuleBundle;
public class WebSiteMeshFilter extends ConfigurableSiteMeshFilter{
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.addDecoratorPath("/strategy/shop/list", "/WEB-INF/views/decorators/decorator.jsp")
// Map decorators to path patterns.
.addDecoratorPath("/strategy/**", "/WEB-INF/views/decorators/decorator.jsp") // Exclude path from decoration.
.addExcludedPath("/login/**")
.addExcludedPath("/main/**")
.addExcludedPath("/popup/**");
builder.addTagRuleBundles(new DivExtractingTagRuleBundle());
}
}
第二部创建WebConfig
类
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WebConfig {
@Bean(name = "sitemesh3")
WebSiteMeshFilter webSiteMeshFilter() {
return new WebSiteMeshFilter();
}
@Bean
public FilterRegistrationBean filterRegistrationBean(@Qualifier("sitemesh3")WebSiteMeshFilter siteMeshFilter) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(siteMeshFilter);
filterRegistrationBean.setEnabled(true);
filterRegistrationBean.addUrlPatterns("/*");
return filterRegistrationBean;
}
}
写这两个类基本上就可以了.