From 2e361e82a000bb496b44ed063f5f832d94e458fb Mon Sep 17 00:00:00 2001 From: thinkgem Date: Fri, 5 Aug 2022 16:31:01 +0800 Subject: [PATCH] replace ad --- .../modules/config/web/DruidStatConfig.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java b/modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java index 4c06596d..2f06b8c0 100644 --- a/modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java +++ b/modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java @@ -4,14 +4,20 @@ */ package com.jeesite.modules.config.web; +import com.alibaba.druid.support.http.StatViewServlet; +import com.alibaba.druid.support.http.WebStatFilter; +import com.alibaba.druid.util.Utils; +import com.jeesite.common.web.http.ServletUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.druid.support.http.StatViewServlet; -import com.alibaba.druid.support.http.WebStatFilter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * Druid 配置 @@ -44,7 +50,19 @@ public class DruidStatConfig { @Bean public ServletRegistrationBean druidServlet() { ServletRegistrationBean bean = new ServletRegistrationBean<>(); - bean.setServlet(new StatViewServlet()); + bean.setServlet(new StatViewServlet(){ + @Override + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String requestURI = request.getRequestURI(); + if (requestURI.endsWith("/druid/js/common.js")) { + String text = Utils.readFromResource("support/http/resources/js/common.js"); + text = text.replaceAll("
", "JeeSite 数据监控, "); + ServletUtils.renderString(response, text, "text/javascript;charset=UTF-8"); + return; + } + super.service(request, response); + } + }); bean.addUrlMappings("/druid/*"); return bean; }