Commit 127b5328 by RuoYi

若依 2.3

parent 92fffea4
......@@ -12,7 +12,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Ds;
import com.ruoyi.framework.datasource.DataSourceContextHolder;
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
/**
* 多数据源处理
......@@ -27,12 +27,12 @@ public class DsAspect
protected Logger logger = LoggerFactory.getLogger(getClass());
@Pointcut("@annotation(com.ruoyi.framework.aspectj.lang.annotation.Ds)")
public void dataSourcePointCut()
public void dsPointCut()
{
}
@Around("dataSourcePointCut()")
@Around("dsPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable
{
MethodSignature signature = (MethodSignature) point.getSignature();
......@@ -44,7 +44,7 @@ public class DsAspect
Ds dataSource = method.getAnnotation(Ds.class);
if (StringUtils.isNotNull(dataSource) && StringUtils.isNotEmpty(dataSource.name()))
{
DataSourceContextHolder.setDB(dataSource.name());
DynamicDataSourceContextHolder.setDB(dataSource.name());
}
}
......@@ -54,7 +54,7 @@ public class DsAspect
}
finally
{
DataSourceContextHolder.clearDB();
DynamicDataSourceContextHolder.clearDB();
}
}
}
......@@ -21,7 +21,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource
@Override
protected Object determineCurrentLookupKey()
{
return DataSourceContextHolder.getDB();
return DynamicDataSourceContextHolder.getDB();
}
}
\ No newline at end of file
......@@ -8,28 +8,35 @@ import org.slf4j.LoggerFactory;
*
* @author ruoyi
*/
public class DataSourceContextHolder
public class DynamicDataSourceContextHolder
{
public static final Logger log = LoggerFactory.getLogger(DataSourceContextHolder.class);
public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class);
private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
// 设置数据源名
/**
* 设置数据源名
*/
public static void setDB(String dbType)
{
log.info("切换到{}数据源", dbType);
contextHolder.set(dbType);
CONTEXT_HOLDER.set(dbType);
}
// 获取数据源名
/**
* 获取数据源名
*/
public static String getDB()
{
return contextHolder.get();
return CONTEXT_HOLDER.get();
}
/**
* 清理数据源名
*/
public static void clearDB()
{
contextHolder.remove();
CONTEXT_HOLDER.remove();
}
}
......@@ -69,7 +69,7 @@ public interface PostMapper
/**
* 校验岗位名称
*
* @param post 岗位信息
* @param postName 岗位名称
* @return 结果
*/
public Post checkPostNameUnique(String postName);
......@@ -77,7 +77,7 @@ public interface PostMapper
/**
* 校验岗位编码
*
* @param post 岗位信息
* @param postCode 岗位编码
* @return 结果
*/
public Post checkPostCodeUnique(String postCode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment