添加分页插件
import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @MapperScan(basePackages = "com.atguigu.mapper") @Configuration public class Mpconfig { //乐观锁插件 @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ //1 创建MybatisPlusInterceptor拦截器对象 MybatisPlusInterceptor mpInterceptor=new MybatisPlusInterceptor(); //添加分页插件 mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return mpInterceptor; } }
测试代码
@Test public void queryUserList(){ Page<User> page = new Page<>(2,3); userMapper.selectPage(page, null); System.out.println("当前页数据:"+page.getRecords()); System.out.println("总分页数量:"+page.getPages()); System.out.println("总记录数量:"+page.getTotal()); System.out.println("是否有下一页:"+page.hasNext()); System.out.println("是否有上一页:"+page.hasPrevious()); }
标签:mybatisPlus,分页,System,查询,MybatisPlusInterceptor,println,import,page,out From: https://www.cnblogs.com/ixtao/p/17321662.html