mybatisplus数据层标准开发---分页功能

1、创建一个拦截器类

复制代码
package com.itheima.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MpConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        // 1、定义Mybatisplus拦截器
        MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
        // 2、添加具体的拦截器(分页)
        mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return  mpInterceptor;
    }
}
复制代码

2、测试分页功能

复制代码
//分页查询
    @Test
    void testGetByPage(){
        //代表第1页,每页2条数据
        IPage page = new Page(1,2);
        userDao.selectPage(page, null);
        System.out.println("当前页码值:" + page.getCurrent());
        System.out.println("每页显示数:" + page.getSize());
        System.out.println("一共多少页:" + page.getPages());
        System.out.println("一共多少条数据:" + page.getTotal());
        System.out.println("每页显示数:" + page.getRecords());

    }
复制代码

 

 3、查看里面的分页sql语句,可在配置文件application.yml中开启日志

 

posted @   佛系粥米  阅读(32)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示