欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MyBatis-Plus?分頁(yè)不生效的解決方法

 更新時(shí)間:2023年05月29日 11:21:54   作者:Tree_walk  
本文主要介紹了MyBatis-Plus?分頁(yè)不生效的解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

分頁(yè)不生效的原因都是攔截器的問題

添加攔截器有兩種情況 在配置類上加攔截器

@Configuration
public class MyBatisPlusConfig {
    /**
     * 新增分頁(yè)攔截器,并設(shè)置數(shù)據(jù)庫(kù)類型為mysql
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 向Mybatis過濾器鏈中添加分頁(yè)攔截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

2.當(dāng)你設(shè)置了數(shù)據(jù)源需要在數(shù)據(jù)源上添加攔截器

@Bean
    public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
        //修改為MybatisSqlSessionFactoryBean
        MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
        //插件類
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        sqlSessionFactoryBean.setDataSource(dataSourceProxy);
        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
        sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory());
        sqlSessionFactoryBean.setGlobalConfig(globalConfig);
        //添加插件
        sqlSessionFactoryBean.setPlugins(mybatisPlusInterceptor);
        return sqlSessionFactoryBean.getObject();
    }

到此這篇關(guān)于MyBatis-Plus 分頁(yè)不生效的解決方法的文章就介紹到這了,更多相關(guān)MyBatis-Plus 分頁(yè)不生效內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論