From e86fd2b2d21215118e66b3ad039c4321f313e8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Thu, 15 Jun 2023 18:14:14 +0800 Subject: [PATCH] optimize Page.java --- .../main/java/com/mybatisflex/core/paginate/Page.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java index f89f7b7e..8b4e75d2 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/paginate/Page.java @@ -24,7 +24,7 @@ import java.util.function.Function; public class Page implements Serializable { private static final long serialVersionUID = 1L; - private static final int INIT_VALUE = -1; + public static final int INIT_VALUE = -1; private List records = Collections.emptyList(); private int pageNumber = INIT_VALUE; @@ -112,9 +112,6 @@ public class Page implements Serializable { } public void setTotalRow(long totalRow) { - if (totalRow < 0) { - throw new IllegalArgumentException("totalRow must greater than or equal 0,current value is: " + totalRow); - } this.totalRow = totalRow; this.calcTotalPage(); } @@ -123,7 +120,9 @@ public class Page implements Serializable { * 计算总页码 */ private void calcTotalPage() { - if (totalPage == INIT_VALUE && pageSize != INIT_VALUE && totalRow != INIT_VALUE) { + if (pageSize < 0 || totalRow < 0) { + totalPage = INIT_VALUE; + } else { totalPage = totalRow % pageSize == 0 ? (totalRow / pageSize) : (totalRow / pageSize + 1); } }