配置类:
package com.oep.backend.config;
import com.baomidou.mybatisplus.annotation.DbType;
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 MybatisConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
实现分页功能:
QueryWrapper<Testpaper> testpaperQueryWrapper = new QueryWrapper<>();
testpaperQueryWrapper.orderByDesc("id");
testpaperQueryWrapper.eq("enterprise_name", enterprise.getName());
IPage<Testpaper> testpaperIPage = new Page<>(1,5); // 查询哪一页以及每页大小
testpaperIPage = testpaperMapper.selectPage(testpaperIPage,testpaperQueryWrapper);
List<Testpaper> list = testpaperIPage.getRecords();
for(Testpaper item: list){ System.out.println(item); } // 当前页数据
System.out.println(testpaperIPage.getPages()); // 总共多少页
System.out.println(testpaperIPage.getCurrent()); // 当前页码
System.out.println(testpaperIPage.getTotal()); // 总记录数
标签:mybatisPlus,分页,System,查询,MybatisPlusInterceptor,testpaperIPage,new,import,testpa
From: https://www.cnblogs.com/twinkler/p/18047131