Bläddra i källkod

新增 PageDto 用于微服务对象传输序列化

hubin 4 år sedan
förälder
incheckning
e15a096a97

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/IPage.java

@@ -50,7 +50,7 @@ public interface IPage<T> extends Serializable {
      *
      * @return true 是 / false 否
      */
-    default boolean isSearchCount() {
+    default boolean searchCount() {
         return true;
     }
 

+ 1 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/PaginationInnerInterceptor.java

@@ -121,7 +121,7 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
     @Override
     public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
         IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
-        if (page == null || page.getSize() < 0 || !page.isSearchCount()) {
+        if (page == null || page.getSize() < 0 || !page.searchCount()) {
             return true;
         }
 

+ 47 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/Page.java

@@ -17,7 +17,6 @@ package com.baomidou.mybatisplus.extension.plugins.pagination;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.OrderItem;
-import lombok.Getter;
 import lombok.Setter;
 
 import java.util.ArrayList;
@@ -58,7 +57,6 @@ public class Page<T> implements IPage<T> {
     /**
      * 排序字段信息
      */
-    @Getter
     @Setter
     protected List<OrderItem> orders = new ArrayList<>();
 
@@ -69,17 +67,15 @@ public class Page<T> implements IPage<T> {
     /**
      * 是否进行 count 查询
      */
-    protected boolean isSearchCount = true;
+    protected boolean searchCount = true;
     /**
      * countId
      */
-    @Getter
     @Setter
     protected String countId;
     /**
      * countId
      */
-    @Getter
     @Setter
     protected Long maxLimit;
 
@@ -100,17 +96,17 @@ public class Page<T> implements IPage<T> {
         this(current, size, total, true);
     }
 
-    public Page(long current, long size, boolean isSearchCount) {
-        this(current, size, 0, isSearchCount);
+    public Page(long current, long size, boolean searchCount) {
+        this(current, size, 0, searchCount);
     }
 
-    public Page(long current, long size, long total, boolean isSearchCount) {
+    public Page(long current, long size, long total, boolean searchCount) {
         if (current > 1) {
             this.current = current;
         }
         this.size = size;
         this.total = total;
-        this.isSearchCount = isSearchCount;
+        this.searchCount = searchCount;
     }
 
     /**
@@ -177,12 +173,12 @@ public class Page<T> implements IPage<T> {
 
     @Override
     public String countId() {
-        return getCountId();
+        return this.countId;
     }
 
     @Override
     public Long maxLimit() {
-        return getMaxLimit();
+        return this.maxLimit;
     }
 
     /**
@@ -238,7 +234,7 @@ public class Page<T> implements IPage<T> {
 
     @Override
     public List<OrderItem> orders() {
-        return getOrders();
+        return this.orders;
     }
 
     @Override
@@ -246,22 +242,16 @@ public class Page<T> implements IPage<T> {
         return optimizeCountSql;
     }
 
-    @Deprecated
-    public boolean isOptimizeCountSql() {
-        return optimizeCountSql();
-    }
-
-    @Deprecated
     @Override
-    public boolean isSearchCount() {
+    public boolean searchCount() {
         if (total < 0) {
             return false;
         }
-        return isSearchCount;
+        return searchCount;
     }
 
-    public Page<T> setSearchCount(boolean isSearchCount) {
-        this.isSearchCount = isSearchCount;
+    public Page<T> setSearchCount(boolean searchCount) {
+        this.searchCount = searchCount;
         return this;
     }
 
@@ -285,11 +275,42 @@ public class Page<T> implements IPage<T> {
         return of(current, size, total, true);
     }
 
-    public static <T> Page<T> of(long current, long size, boolean isSearchCount) {
-        return of(current, size, 0, isSearchCount);
+    public static <T> Page<T> of(long current, long size, boolean searchCount) {
+        return of(current, size, 0, searchCount);
     }
 
-    public static <T> Page<T> of(long current, long size, long total, boolean isSearchCount) {
-        return new Page(current, size, total, isSearchCount);
+    public static <T> Page<T> of(long current, long size, long total, boolean searchCount) {
+        return new Page(current, size, total, searchCount);
+    }
+
+    /*
+     * --begin------------- 未来抛弃移除的方法 -------------begin--
+     * 该部分属性转移至 com.baomidou.mybatisplus.core.metadata.OrderItem.PageDto
+     */
+    @Deprecated
+    public String getCountId() {
+        return this.countId;
+    }
+
+    @Deprecated
+    public Long getMaxLimit() {
+        return this.maxLimit;
     }
+
+    @Deprecated
+    public List<OrderItem> getOrders() {
+        return this.orders;
+    }
+
+    @Deprecated
+    public boolean isOptimizeCountSql() {
+        return this.optimizeCountSql;
+    }
+
+    @Deprecated
+    public boolean isSearchCount() {
+        return this.searchCount;
+    }
+    /* --end------------- 未来抛弃移除的方法 -------------end-- */
+
 }

+ 49 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/PageDto.java

@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.baomidou.mybatisplus.extension.plugins.pagination;
+
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+
+import java.util.List;
+
+/**
+ * 简单分页模型 DTO 用于解决跨服务数据传输问题,不影响 Page 作为返回对象序列化 JSON 产生不必要的数据
+ *
+ * @author hubin
+ * @since 2021-05-20
+ */
+public class PageDto<T> extends Page<T> {
+
+    public String getCountId() {
+        return this.countId;
+    }
+
+    public Long getMaxLimit() {
+        return this.maxLimit;
+    }
+
+    public List<OrderItem> getOrders() {
+        return this.orders;
+    }
+
+    public boolean isOptimizeCountSql() {
+        return this.optimizeCountSql;
+    }
+
+    public boolean isSearchCount() {
+        return this.searchCount;
+    }
+}