Mybatis-Plus 中的分页查询接口主要有两个:IPage 和 Page。
IPage 接口:
IPage 是 Mybatis-Plus 中的分页结果集接口,它继承了 Mybatis 的 RowBounds 接口,提供了一系列的分页查询方法。该接口主要用于返回分页后的数据结果。
Page 类:
Page 类是 IPage 接口的默认实现类,实现了 IPage 接口中的方法。在进行分页查询时,通常会创建一个 Page 对象,并设置相关的分页参数。
以下是 IPage 和 Page 类的常用参数:
current:当前页数,必须大于等于 1,默认值为 1。
size:每页条数,默认值为 10。
total:总条数,默认值为 0。
records:当前页数据集合,默认值为空集合。
searchCount:是否进行 count 查询,默认值为 true,表示会统计总条数。
pages:总页数,通过计算得出。
optimizeCountSql:是否优化 count 查询,默认值为 true。
hitCount:是否对 count 进行 limit 优化,默认值为 false。
countId:count 查询的列名,默认为 null,表示所有列。
maxLimit:设置最大的 limit 查询限制,默认值为 -1,表示不限制。
IPage<CustomerVO> page=new Page<>(customerDTO.getPageNum(),customerDTO.getPageSize());
IPage<CustomerVO> sysUserList= userMapper. selectCustomerList(page,customerDTO);
IPage<CustomerVO> selectCustomerList(@Param("page")IPage<CustomerVO> page ,@Param("customerDTO") CustomerDTO customerDTO);
别忘了开启分页
/**
* 启动程序
*
* @author ruoyi
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, scanBasePackages = {"com.cgwenjian", "com.cgwenjian"})
@EnableAsync
public class Application {
public static void main(String[] args) {
// System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(Application.class, args);
System.out.println("【文兜智写启动成功】");
}
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 添加分页插件
return interceptor;
}
}