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