首页>代码>ssm+shiro+layui+quartz实现细粒度用户权限控制>/app_demo/src/main/java/com/bird/business/annotation/DataSourceAspect.java
package com.bird.business.annotation; import org.apache.commons.lang.StringUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import java.lang.reflect.Method; @Aspect @Component public class DataSourceAspect { //配置接入点 @Pointcut("execution(* com.bird.business.controller..*.*(..))") private void controllerAspect(){}//定义一个切入点 @Before("controllerAspect()") public void dataSwitch(JoinPoint joinPoint){ Signature signature = joinPoint.getSignature(); MethodSignature methodSignature =(MethodSignature) signature; Method method = methodSignature.getMethod(); DataSource data = null; String dataSource = ""; if(method != null){ data = method.getAnnotation(DataSource.class); if(data != null){ //获取dataSource注解的参数值 dataSource = data.dataSource(); if(!StringUtils.isBlank(dataSource)){ DynamicDataSource.setDataSourceKey(dataSource); } } else { //spring-mybatis.xml配置了默认的数据源,但是两个数据源之间存在乱跳 //此处做配置,若没有使用DataSource注解,设置默认数据源 DynamicDataSource.setDataSourceKey("dataSource"); } } } }
最近下载更多
Brilion LV6
2023年3月22日
admin115 LV6
2022年11月30日
543666826 LV33
2021年11月20日
zhoulang123 LV8
2021年5月6日
Xavier1123 LV8
2021年4月22日
breakCY LV15
2021年4月9日
xhmpmail LV17
2021年2月23日
123456nty LV36
2020年12月7日
hello-world LV10
2020年9月24日
qwicheng LV1
2020年9月22日
最近浏览更多
xuweiwowzy LV5
1月14日
ljt289917726 LV3
2023年12月8日
Hachi6 LV13
2023年10月11日
monster536
2023年8月28日
暂无贡献等级
skook7 LV2
2023年6月1日
女王不该在山炮村养花 LV8
2023年4月17日
wiston
2023年3月30日
暂无贡献等级
黑 LV6
2023年3月29日
微信网友_6406149708648448
2023年3月26日
暂无贡献等级
Brilion LV6
2023年3月22日