首页>代码>spring boot + mybatis(通用mapper) druid多数据源切换配置>/demo-boot-multdata/src/main/java/com/xe/demo/common/ds/DynamicDataSourceAspect.java
package com.xe.demo.common.ds;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * 切换数据源
 * @author CZH
 */
@Aspect
@Component
public class DynamicDataSourceAspect {

	/**
	 * 根据@TargetDataSource的属性值设置不同的dataSourceKey,以供DynamicDataSource
	 * @param point
	 * @param ds
	 * @throws Throwable
	 */
    @Before("@annotation(ds)")
    public void changeDataSource(JoinPoint point, TargetDataSource ds) throws Throwable {
        DynamicDataSource.setDataSourceType(ds.value());
    }

    /**
     * 方法执行完毕后清除数据源
     * @param point
     * @param ds
     */
    @After("@annotation(ds)")
    public void restoreDataSource(JoinPoint point, TargetDataSource ds) {
        DynamicDataSource.clearDataSourceType();
    }

}
最近下载更多
123456ym  LV9 2022年4月27日
maojianyun  LV30 2022年4月13日
1214066599  LV8 2022年4月4日
wsupsup  LV16 2021年9月22日
xxxjjj123  LV6 2021年7月30日
小海脑洞大开  LV11 2021年7月29日
alin007  LV5 2019年12月23日
koumeiyuu  LV8 2019年12月18日
qiheideguang  LV16 2019年9月9日
sksd520  LV3 2019年8月8日
最近浏览更多
genyuan2014  LV4 4月27日
安东尼online  LV11 1月16日
dengjunjun  LV15 2023年1月5日
123456ym  LV9 2022年4月27日
1214066599  LV8 2022年4月4日
jy1218  LV12 2022年1月18日
Hachi6  LV13 2021年12月20日
采暖11  LV11 2021年11月23日
mugege123  LV6 2021年11月16日
wsupsup  LV16 2021年9月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友