Score
0
Watch 3.5K Star 9.2K Fork 4K

卓源软件 / JeeSite 4.2JavaAGPL-3.0

druid的广告可以删了

Open
bilifuture  Opened this issue

输入图片说明

解决办法:

@Configuration
@ConditionalOnWebApplication
@AutoConfigureAfter(DruidDataSourceAutoConfigure.class)
@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true", matchIfMissing = true)
public class RemoveDruidAdvertisingConfig {
	 /**   
	 * @Title: removeDruidAdFilterRegistrationBean   
	 * @Description: 除去页面底部的广告
	 * @param: @param properties
	 * @param: @return      
	 * @return: FilterRegistrationBean      
	 * @throws   
	 */  
	@SuppressWarnings("all")
	@Bean
    public FilterRegistrationBean removeDruidAdFilterRegistrationBean(DruidStatProperties properties) {
		
		/**
		 * 	获取监控页面参数
		 */
        DruidStatProperties.StatViewServlet druidConfig = properties.getStatViewServlet();
        /**
         *	 获取common.js位置
         */
        String pattern = druidConfig.getUrlPattern() != null ? druidConfig.getUrlPattern() : "/druid/*";
        String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
        final String filePath = "support/http/resources/js/common.js";
        
        /**
         * 	 利用Filter进行过滤
         */
        Filter filter = new Filter() {
            @Override
            public void init(FilterConfig filterConfig) throws ServletException {
            }
            @Override
            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
                chain.doFilter(request, response);
                response.resetBuffer();
                /**
               	 * 		获取common文件内容
               	 */
                String text = Utils.readFromResource(filePath);
                /**
                 *		 利用正则表达式删除<footer class="footer">中的<a>标签
                 */
                text = text.replaceAll("<a.*?banner\"></a><br/>", "");
                text = text.replaceAll("powered.*?shrek.wang</a>", "");
                response.getWriter().write(text);
            }

            @Override
            public void destroy() {
            }
        };	
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(filter);
        registrationBean.addUrlPatterns(commonJsPattern);
        return registrationBean;
    }
}
total 1 participants

Comments (0)

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority
Java
1
https://gitee.com/thinkgem/jeesite4.git
git@gitee.com:thinkgem/jeesite4.git
thinkgem
jeesite4
JeeSite 4.2

Search