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」创作共享协议,转载请在文章明显位置注明作者及出处。

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

posted @ 2020-09-15 15:26  java锋哥  阅读(1912)  评论(0编辑  收藏  举报