MyBatis-Plus?分頁(yè)不生效的解決方法
分頁(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)文章
Java程序的初始化順序,static{}靜態(tài)代碼塊和實(shí)例語(yǔ)句塊的使用方式
這篇文章主要介紹了Java程序的初始化順序,static{}靜態(tài)代碼塊和實(shí)例語(yǔ)句塊的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01spring boot udp或者tcp接收數(shù)據(jù)的實(shí)例詳解
這篇文章主要介紹了spring boot udp或者tcp接收數(shù)據(jù),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12Java常用數(shù)字工具類 大數(shù)乘法、加法、減法運(yùn)算(2)
這篇文章主要為大家詳細(xì)介紹了Java常用數(shù)字工具類,大數(shù)乘法、加法、減法運(yùn)算,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05IDEA 使用mybatis插件Free Mybatis plugin的步驟(推薦)
這篇文章主要介紹了IDEA 使用mybatis插件Free Mybatis plugin的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12java編程實(shí)現(xiàn)屏幕截圖(截屏)代碼總結(jié)
這篇文章主要介紹了java編程實(shí)現(xiàn)屏幕截圖(截屏)代碼,結(jié)合3個(gè)實(shí)例總結(jié)分析了Java截屏?xí)r頁(yè)面抓取及圖片保存的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11MyBatis-Plus動(dòng)態(tài)返回實(shí)體類示例詳解
這篇文章主要為大家介紹了MyBatis-Plus動(dòng)態(tài)返回實(shí)體類示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07