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中开启日志
标签:mybatisplus,分页,System,---,MybatisPlusInterceptor,println,page,out From: https://www.cnblogs.com/fxzm/p/17131639.html