SpringBoot使用Mybatis-Plus分页无效

见注释

@Configuration
@MapperScan(basePackages = {"com.test.collection"}, sqlSessionFactoryRef = "collectionSqlSessionFactory")
public class CollectionMyBatisConfig {

    @Bean(name = "collection")
    @ConfigurationProperties(prefix = "spring.datasource.collection")
    public DataSource dataSource() {
        return new DruidDataSource();
    }
	// 1. 如果配置了自定义的SqlSessionFactory
    @Bean(name = "collectionSqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory(@Qualifier("collection") DataSource dataSource) throws Exception {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        com.baomidou.mybatisplus.core.MybatisConfiguration configuration = new com.baomidou.mybatisplus.core.MybatisConfiguration();
        configuration.setMapUnderscoreToCamelCase(false);
        bean.setConfiguration(configuration);
		// 3. 可以选择把拦截器驾到configuration里面
		
        bean.setDataSource(dataSource);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/collection/*.xml"));
        return bean.getObject();
    }

    @Bean(name = "collectionTransactionManager")
    public DataSourceTransactionManager transactionManager(@Qualifier("collection") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean(name = "collectionSqlSessionTemplate")
    public SqlSessionTemplate sqlSessionTemplate(@Qualifier("collectionSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
        return new SqlSessionTemplate(sqlSessionFactory);
    }

	// 2. 这个拦截器加了就无效,这应该是加到了默认的SqlSessionFactory里面
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值