页面广告问题

This commit is contained in:
dingzhongyuan 2021-06-21 16:17:42 +08:00
parent 3a217c9ea2
commit e7e91ecd7b
5 changed files with 91 additions and 145 deletions

View File

@ -5,6 +5,15 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
dynamic:
druid:
# 初始连接数
@ -12,7 +21,7 @@ spring:
# 最小连接池数量
minIdle: 10
# 最大连接池数量
maxActive: 20
maxActive: 30
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
@ -29,14 +38,6 @@ spring:
filters: stat # 注意这个值和druid原生不一致默认启动了stat
webStatFilter:
enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
filter:
stat:
enabled: true
@ -54,10 +55,10 @@ spring:
username: root
password: root123456
# 从库数据源
slave:
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: root123456
# slave:
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
# username: root
# password: root123456
# redis 配置
redis:
# 地址

View File

@ -1,22 +1,20 @@
# 数据源配置
spring:
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
dynamic:
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: root123456
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
# 初始连接数
initialSize: 5
# 最小连接池数量
@ -36,6 +34,7 @@ spring:
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
filters: stat # 注意这个值和druid原生不一致默认启动了stat
webStatFilter:
enabled: true
statViewServlet:
@ -56,6 +55,17 @@ spring:
wall:
config:
multi-statement-allow: true
datasource:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: root123456
# 从库数据源
# slave:
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
# username: root
# password: root123456
# redis 配置
redis:

View File

@ -1,73 +0,0 @@
//package com.ruoyi.framework.aspectj;
//
//import cn.hutool.core.lang.Validator;
//import com.ruoyi.common.annotation.DataSource;
//import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.core.annotation.AnnotationUtils;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import java.util.Objects;
//
///**
// * 多数据源处理
// *
// * @author ruoyi
// */
//@Aspect
//@Order(1)
//@Component
//public class DataSourceAspect
//{
// protected Logger logger = LoggerFactory.getLogger(getClass());
//
// @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
// + "|| @within(com.ruoyi.common.annotation.DataSource)")
// public void dsPointCut()
// {
//
// }
//
// @Around("dsPointCut()")
// public Object around(ProceedingJoinPoint point) throws Throwable
// {
// DataSource dataSource = getDataSource(point);
//
// if (Validator.isNotNull(dataSource))
// {
// DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
// }
//
// try
// {
// return point.proceed();
// }
// finally
// {
// // 销毁数据源 在执行方法之后
// DynamicDataSourceContextHolder.clearDataSourceType();
// }
// }
//
// /**
// * 获取需要切换的数据源
// */
// public DataSource getDataSource(ProceedingJoinPoint point)
// {
// MethodSignature signature = (MethodSignature) point.getSignature();
// DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
// if (Objects.nonNull(dataSource))
// {
// return dataSource;
// }
//
// return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
// }
//}

View File

@ -1,11 +1,19 @@
package com.ruoyi.framework.config;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.util.Utils;
import com.baomidou.dynamic.datasource.plugin.MasterSlaveAutoRoutingPlugin;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.servlet.*;
import java.io.IOException;
/**
* 在纯的读写分离环境写操作全部是master读操作全部是slave
* @author ding
@ -18,50 +26,50 @@ public class DynamicDataSourceConfig {
return new MasterSlaveAutoRoutingPlugin();
}
// /**
// * 去除监控页面底部的广告
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// @Bean
// @ConditionalOnProperty(name = "spring.datasource.dynamic.druid.statViewServlet.enabled", havingValue = "true")
// public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
// {
// // 获取web监控页面的参数
// DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// // 提取common.js的配置路径
// String pattern = config.getUrlPattern() != null ? config.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(javax.servlet.FilterConfig filterConfig) throws ServletException
// {
// }
// @Override
// public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
// throws IOException, ServletException
// {
// chain.doFilter(request, response);
// // 重置缓冲区响应头不会被重置
//// response.resetBuffer();
// // 获取common.js
// String text = Utils.readFromResource(filePath);
// // 正则替换banner, 除去底部的广告信息
// 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;
// }
/**
* 去除监控页面底部的广告
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true")
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
{
// 获取web监控页面的参数
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// 提取common.js的配置路径
String pattern = config.getUrlPattern() != null ? config.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(javax.servlet.FilterConfig filterConfig) throws ServletException
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
chain.doFilter(request, response);
// 重置缓冲区响应头不会被重置
// response.resetBuffer();
// 获取common.js
String text = Utils.readFromResource(filePath);
// 正则替换banner, 除去底部的广告信息
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;
}
}

View File

@ -56,7 +56,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
@DS("master")
@DS("slave")
public TableDataInfo<SysUser> selectPageUserList(SysUser user) {
String dataName = DynamicDataSourceContextHolder.peek();
log.info("自定义方法--获取用户列表---当前数据源名称:"+dataName);