mybatis-plus物理分頁插件使用


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」創作共享協議,轉載請在文章明顯位置注明作者及出處。

------------------------------------------------------------------------------------------------------------------------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM