MyBatisPlus插件扩展_PaginationInterceptor分页插件的使用
生活随笔
收集整理的這篇文章主要介紹了
MyBatisPlus插件扩展_PaginationInterceptor分页插件的使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
場景
項目搭建專欄:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194
實現(xiàn)
配置插件
來到項目下的applicationContext.xml中配置sqlSessionFactoryBean的地方。
<!--? 配置SqlSessionFactoryBeanMybatis提供的: org.mybatis.spring.SqlSessionFactoryBeanMP提供的:com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean--><bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"><!-- 數(shù)據(jù)源 --><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:mybatis-config.xml"></property><!-- 別名處理 --><property name="typeAliasesPackage" value="com.badao.beans"></property>?<!-- 注入全局MP策略配置 --><property name="globalConfig" ref="globalConfiguration"></property>?<!-- 插件注冊 --><property name="plugins"><list><!-- 注冊分頁插件 --><bean class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"></bean></list></property>?</bean>測試分頁插件
編寫單元測試
/**** 分頁插件*/@Testpublic void testPagePlugin() {Page<Employee> page = new Page<Employee>(1,2);List<Employee> list=employeeMapper.selectPage(page, null);for (?Employee employee : list) {System.out.println("*******************"+employee.getName());}System.out.println("獲取分頁信息");System.out.println("總條數(shù)"+page.getTotal());System.out.println("當前頁碼"+page.getCurrent());System.out.println("總頁碼"+page.getPages());System.out.println("每頁顯示的條數(shù)"+page.getSize());System.out.println("是否有上一頁"+page.hasPrevious());System.out.println("是否有下一頁"+page.hasNext());//將查詢的結(jié)果直接封裝到page對象中page.setRecords(list);}Page對象
實現(xiàn)分頁輔助類
?
繼承了Pagination,所以也繼承了方法。
運行單元測試
源碼下載
https://download.csdn.net/download/badao_liumang_qizhi/11147534
總結(jié)
以上是生活随笔為你收集整理的MyBatisPlus插件扩展_PaginationInterceptor分页插件的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MyBatisPlus的ActiveRe
- 下一篇: MyBatisPlus插件扩展_SqlE