MyBatis-Plus中Page类
MyBatisPlus在使用分页时需要传入一个Page对象,这里对该对象做一些解释
打开Page的源码我们可以看到Page实现了IPage接口
private static final long serialVersionUID = 8545996863226528798L;
protected List<T> records;
protected long total;
protected long size;
protected long current;
protected List<OrderItem> orders;
protected boolean optimizeCountSql;
protected boolean isSearchCount;
protected boolean hitCount;
protected String countId;
protected Long maxLimit;
而它的构造参数居然有5个,让我们眼花缭乱。因此在这里对每一个参数进行一个详细的介绍。
| 参数名 | 参数类型 | 默认值 | 描述 |
|---|---|---|---|
| records | List<T> | 用来存放查询出来的数据 | |
| total | long | 返回记录的总数 | |
| size | long | 10 | 每页显示条数 |
| current | long | 1 | 当前页 |
| orders | List<OrderItem> | 排序字段信息 | |
| optimizeCountSql | boolean | true | 自动优化 COUNT SQL |
| isSearchCount | boolean | true | 是否进行 count 查询,设置false后不会返回total |
| hitCount | boolean | false | 是否命中count缓存 |
| countId | String | ||
| maxLimit | Long | null | 单页分页条数限制 |
MyBatis-Plus的Page类是实现分页查询的关键,它包含了查询结果、总记录数、每页大小、当前页数等核心属性。通过构造函数的五个参数,如records、total、size、current和orders,可以灵活配置分页和排序。optimizeCountSql用于自动优化COUNT SQL,isSearchCount决定了是否执行计数查询,hitCount涉及缓存策略,countId与特定的计数查询ID相关,而maxLimit则限制了单页的最大分页条数。
1万+





