欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot 整合 sitemesh3

程序员文章站 2022-03-02 14:38:19
...

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;   
  }
}

写这两个类基本上就可以了.



作者:蒙奇D鲁班
链接:https://www.jianshu.com/p/f81912837d44
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

相关标签: springboot