数据源表(DS表)

定义:数据源表指的是从外部数据源(如数据库、文件、API等)直接抽取的原始数据表。这些表中的数据通常是未经过大规模处理或加工的原始状态。

特点:

数据源表是未经过业务逻辑处理的原始数据,可能包含多种数据类型和格式。

主要用于数据的采集、存储和初步清洗,以保留数据的原始状态和完整性。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot中,我们可以使用多个数据,但是默认情况下只能使用一个数据。如果我们想要使用多个数据,我们可以使用Dynamic DataSource Routing(动态数据路由)来解决这个问题。Dynamic DataSource Routing可以根据当前线程的上下文信息来动态地切换数据。 在使用Dynamic DataSource Routing之前,我们需要使用Spring Boot的AOP功能来拦截MyBatis的Mapper接口,并根据当前线程的上下文信息来动态地切换数据。具体步骤如下: 1.添加依赖 ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>${dynamic.datasource.version}</version> </dependency> ``` 2.配置数据 ```yaml spring: datasource: master: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false username: root password: root driver-class-name: com.mysql.jdbc.Driver slave1: url: jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false username: root password: root driver-class-name: com.mysql.jdbc.Driver ``` 3.配置动态数据 ```java @Configuration public class DataSourceConfig { @Bean @ConfigurationProperties(prefix = "spring.datasource.master") public DataSource masterDataSource() { return DataSourceBuilder.create().build(); } @Bean @ConfigurationProperties(prefix = "spring.datasource.slave1") public DataSource slave1DataSource() { return DataSourceBuilder.create().build(); } @Bean public DynamicDataSource dynamicDataSource(@Qualifier("masterDataSource") DataSource masterDataSource, @Qualifier("slave1DataSource") DataSource slave1DataSource) { Map<Object, Object> targetDataSources = new HashMap<>(); targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); targetDataSources.put(DataSourceType.SLAVE1.name(), slave1DataSource); return new DynamicDataSource(masterDataSource, targetDataSources); } } ``` 4.配置AOP ```java @Aspect @Component public class DataSourceAspect { @Pointcut("@annotation(com.baomidou.dynamic.datasource.annotation.DS)") public void dsPointCut() { } @Before("dsPointCut()") public void beforeSwitchDS(JoinPoint point) { MethodSignature signature = (MethodSignature) point.getSignature(); DS annotation = signature.getMethod().getAnnotation(DS.class); if (annotation == null) { DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER); } else { DynamicDataSourceContextHolder.setDataSourceType(annotation.value()); } } @After("dsPointCut()") public void afterSwitchDS(JoinPoint point) { DynamicDataSourceContextHolder.clearDataSourceType(); } } ``` 5.使用@DS注解来动态指定数据 ```java @DS("slave1") public interface UserMapper { List<User> findAll(); } ``` 以上就是在Spring Boot中配置多数据的方法,通过Dynamic DataSource Routing来实现动态切换数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值