mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 多数据源切换标注过期 3.6.0 移除 推荐使用原生注解
This commit is contained in:
		@@ -95,6 +95,13 @@
 | 
			
		||||
            <groupId>com.baomidou</groupId>
 | 
			
		||||
            <artifactId>mybatis-plus-extension</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <!-- dynamic-datasource 多数据源-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.baomidou</groupId>
 | 
			
		||||
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>cn.hutool</groupId>
 | 
			
		||||
            <artifactId>hutool-all</artifactId>
 | 
			
		||||
 
 | 
			
		||||
@@ -10,11 +10,13 @@ import java.lang.annotation.*;
 | 
			
		||||
 * 优先级:先方法,后类,如果方法覆盖了类上的数据源类型,以方法的为准,否则以类上的为准
 | 
			
		||||
 *
 | 
			
		||||
 * @author ruoyi
 | 
			
		||||
 * @deprecated 3.6.0 移除 使用原生注解处理 方法更全 {@link com.baomidou.dynamic.datasource.annotation.DS}
 | 
			
		||||
 */
 | 
			
		||||
@Target({ElementType.METHOD, ElementType.TYPE})
 | 
			
		||||
@Retention(RetentionPolicy.RUNTIME)
 | 
			
		||||
@Documented
 | 
			
		||||
@Inherited
 | 
			
		||||
@Deprecated
 | 
			
		||||
public @interface DataSource {
 | 
			
		||||
    /**
 | 
			
		||||
     * 切换数据源名称
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,10 @@ import lombok.Getter;
 | 
			
		||||
 * 数据源
 | 
			
		||||
 *
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 * @deprecated 3.6.0 移除
 | 
			
		||||
 */
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@Deprecated
 | 
			
		||||
public enum DataSourceType {
 | 
			
		||||
    /**
 | 
			
		||||
     * 主库
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ import java.util.Map;
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 * @date 2021-07-26
 | 
			
		||||
 */
 | 
			
		||||
//@DataSource(DataSourceType.SLAVE) // 切换从库查询
 | 
			
		||||
// @DS("slave") // 切换从库查询
 | 
			
		||||
@Service
 | 
			
		||||
public class TestTreeServiceImpl extends ServicePlusImpl<TestTreeMapper, TestTree, TestTreeVo> implements ITestTreeService {
 | 
			
		||||
 | 
			
		||||
@@ -32,7 +32,7 @@ public class TestTreeServiceImpl extends ServicePlusImpl<TestTreeMapper, TestTre
 | 
			
		||||
		return getVoById(id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
//	@DataSource(DataSourceType.SLAVE) // 切换从库查询
 | 
			
		||||
//	@DS("slave") // 切换从库查询
 | 
			
		||||
    @DataScope(isUser = true)
 | 
			
		||||
	@Override
 | 
			
		||||
	public List<TestTreeVo> queryList(TestTreeBo bo) {
 | 
			
		||||
 
 | 
			
		||||
@@ -46,11 +46,6 @@
 | 
			
		||||
            <artifactId>druid-spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
        <!-- dynamic-datasource 多数据源-->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.baomidou</groupId>
 | 
			
		||||
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <!-- sql性能分析插件 -->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>p6spy</groupId>
 | 
			
		||||
 
 | 
			
		||||
@@ -18,10 +18,12 @@ import java.util.Objects;
 | 
			
		||||
 * 多数据源处理
 | 
			
		||||
 *
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 * @deprecated 3.6.0 移除 使用原生方法处理 功能更全
 | 
			
		||||
 */
 | 
			
		||||
@Aspect
 | 
			
		||||
@Order(-500)
 | 
			
		||||
@Component
 | 
			
		||||
@Deprecated
 | 
			
		||||
public class DataSourceAspect {
 | 
			
		||||
 | 
			
		||||
	@Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,7 @@ public class SysConfigServiceImpl extends ServicePlusImpl<SysConfigMapper, SysCo
 | 
			
		||||
     * @return 参数配置信息
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    @DataSource(DataSourceType.MASTER)
 | 
			
		||||
    @DS("master")
 | 
			
		||||
    public SysConfig selectConfigById(Long configId) {
 | 
			
		||||
        return baseMapper.selectById(configId);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user