update 多数据源切换标注过期 3.6.0 移除 推荐使用原生注解
| | |
| | | <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> |
| | |
| | | * 优先级:先方法,后类,如果方法覆盖了类上的数据源类型,以方法的为准,否则以类上的为准 |
| | | * |
| | | * @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 { |
| | | /** |
| | | * 切换数据源名称 |
| | |
| | | * 数据源 |
| | | * |
| | | * @author Lion Li |
| | | * @deprecated 3.6.0 移除 |
| | | */ |
| | | @AllArgsConstructor |
| | | @Deprecated |
| | | public enum DataSourceType { |
| | | /** |
| | | * 主库 |
| | |
| | | * @author Lion Li |
| | | * @date 2021-07-26 |
| | | */ |
| | | //@DataSource(DataSourceType.SLAVE) // 切换从库查询 |
| | | // @DS("slave") // 切换从库查询 |
| | | @Service |
| | | public class TestTreeServiceImpl extends ServicePlusImpl<TestTreeMapper, TestTree, TestTreeVo> implements ITestTreeService { |
| | | |
| | |
| | | return getVoById(id); |
| | | } |
| | | |
| | | // @DataSource(DataSourceType.SLAVE) // 切换从库查询 |
| | | // @DS("slave") // 切换从库查询 |
| | | @DataScope(isUser = true) |
| | | @Override |
| | | public List<TestTreeVo> queryList(TestTreeBo bo) { |
| | |
| | | <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> |
| | |
| | | * 多数据源处理 |
| | | * |
| | | * @author Lion Li |
| | | * @deprecated 3.6.0 移除 使用原生方法处理 功能更全 |
| | | */ |
| | | @Aspect |
| | | @Order(-500) |
| | | @Component |
| | | @Deprecated |
| | | public class DataSourceAspect { |
| | | |
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)" |
| | |
| | | * @return 参数配置信息 |
| | | */ |
| | | @Override |
| | | @DataSource(DataSourceType.MASTER) |
| | | @DS("master") |
| | | public SysConfig selectConfigById(Long configId) { |
| | | return baseMapper.selectById(configId); |
| | | } |