The environment
Configuration information
The libraries are PostgresQL and mysql. Postgresql is the master library by default
The configuration information is as follows
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl spring.datasource.dynamic.primary=postgresql spring.datasource.dynamic.strict=true spring.datasource.dynamic.datasource.mysql.url=jdbc:mysql://localhost:3306/spring_boot_test? serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false spring.datasource.dynamic.datasource.mysql.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.dynamic.datasource.mysql.username=root spring.datasource.dynamic.datasource.mysql.password=123456
spring.datasource.dynamic.datasource.postgresql.url=jdbc:postgresql://localhost:7092/postgres spring.datasource.dynamic.datasource.postgresql.driver-class-name=org.postgresql.Driver spring.datasource.dynamic.datasource.postgresql.username=postgres spring.datasource.dynamic.datasource.postgresql.password=123456
Mapper file
Use DS to specify the database to operate on
@DS("postgresql")
@Mapper
public interface CtmAskForLeaveMapper extends BaseMapper<CtmAskForLeave> {
}
Copy the code
@DS("mysql")
@Mapper
public interface CtmThirdAskForLeaveMapper extends BaseMapper<CtmThirdAskForLeave> {
}
Copy the code
Rewrite SqlSessionFactory
Invalid bound Statement (not found) Invalid bound Statement (not found) Invalid bound Statement (not found)
@configuration @mapperscan ("mappper ") public class MybatisPlusConfig {** ** pagination plugin */ @bean public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); } @Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*/*.xml")); sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); sqlSessionFactoryBean.setPlugins(new Interceptor[]{paginationInterceptor()}); return sqlSessionFactoryBean.getObject(); }}Copy the code
The test code
`public interface CtmAskForLeaveService extends IService {
@return */ Boolean messageAskForLeave();Copy the code
}
@Service @Slf4j public class CtmAskForLeaveServiceImpl extends ServiceImpl<CtmAskForLeaveMapper, CtmAskForLeave> implements CtmAskForLeaveService {
@Override
public Boolean messageAskForLeave() {
List<CtmThirdAskForLeave> ctmThirdAskForLeaves = ctmThirdAskForLeaveMapper.selectList(null);
}
Copy the code
} `