@@ -180,7 +180,7 @@ public class PaginationInterceptor extends AbstractSqlParserHandler implements I
LongSupplier supplier = page.getSupplier();
boolean orderBy = true;
- if (page.getTotal() < 0) {
+ if (page.getTotal() == 0) {
// total 为0 才进行 count
SqlInfo sqlInfo = SqlParserUtils.getOptimizeCountSql(page.optimizeCountSql(), sqlParser, originalSql);
orderBy = sqlInfo.isOrderBy();
@@ -39,9 +39,9 @@ public class Page<T> implements IPage<T> {
*/
private List<T> records = Collections.emptyList();
/**
- * 总数,当 total 大于等于 0 时分页插件不会进行 count 查询
+ * 总数,当 total 不为 0 时分页插件不会进行 count 查询
- private long total = -1;
+ private long total = 0;
* 每页显示条数,默认 10
@@ -96,7 +96,12 @@ public class Page<T> implements IPage<T> {
this.current = current;
}
this.size = size;
- this.total = total;
+ if (0 == total) {
+ // 通过构造函数自定义 count sql 的值为 0 设置 -1 不查询分页总数
+ this.total = -1;
+ } else {
+ this.total = total;
+ }