mp框架提供了物理分頁插件,我們下面來看下如何實現:
首先配置一個PaginationInterceptor的bean;
package com.java1234.config; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * MybatisPlus配置類 * @author java1234_小鋒 * @site www.java1234.com * @company Java知識分享網 * @create 2020-09-07 14:03 */ @Configuration public class MybatisPlusConfig { /** * mybatis-plus分頁插件 * @return */ @Bean public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); } }
帶分頁查詢:
/** * 查找薪水大於3200 帶分頁 * sql: select * from t_employee where salary>3200 */ @Test public void selectByQueryWrapperWithPage(){ QueryWrapper<Employee> queryWrapper=new QueryWrapper(); queryWrapper.gt("salary",3200); Page<Employee> page = new Page<>(1, 3); Page<Employee> employeePage = employeeMapper.selectPage(page, queryWrapper); System.out.println("總記錄數:"+employeePage.getTotal()); System.out.println("總頁數:"+employeePage.getPages()); System.out.println("當前頁數據:"+employeePage.getRecords()); }
------------------------------------------------------------------------------------------------------------------------------
作者: java1234_小鋒
出處:https://www.cnblogs.com/java688/p/13672095.html
版權:本站使用「CC BY 4.0」創作共享協議,轉載請在文章明顯位置注明作者及出處。
------------------------------------------------------------------------------------------------------------------------------