切换数据库用户

public class MultiDataSource extends AbstractRoutingDataSource {

    private static final ThreadLocal<String> dataSourceKey = new InheritableThreadLocal<>();

    public static void setCurrentDataSource(String dataSource)
    {
        dataSourceKey.set(dataSource);
    }

    public static String getDsKey(){
        return dataSourceKey.get();
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return dataSourceKey.get();
    }
}
 MultiDataSource.setCurrentDataSource(DataSourceKey.DAP);

猜你喜欢

转载自www.cnblogs.com/singworld/p/11713305.html