java1234开源博客系统
博客信息

mybatis-plus物理分页插件使用

0
发布时间:『 2020-09-07 16:28』  博客类别:mybatis-plus  阅读(2583) 评论(0)

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微信公众号
博主信息
Java1234_小锋
(知识改变命运,技术改变世界)
Powered by Java1234 V3.0 Copyright © 2012-2016 Java知识分享网 版权所有