Selaa lähdekoodia

增加通用的分页查询结果类,以及mybatis-plus模块中BaseQuery的转换方法

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 3 vuotta sitten
vanhempi
commit
7cc161a1f7

+ 59 - 0
core-models/src/main/java/com/qmth/boot/core/collection/PageResult.java

@@ -0,0 +1,59 @@
+package com.qmth.boot.core.collection;
+
+import java.util.List;
+
+/**
+ * 通用分页查询结果封装类,适用于API层的数据返回
+ */
+public class PageResult<T> {
+
+    private List<T> result;
+
+    private long totalCount;
+
+    private long pageCount;
+
+    private long pageNumber;
+
+    private long pageSize;
+
+    public List<T> getResult() {
+        return result;
+    }
+
+    public void setResult(List<T> result) {
+        this.result = result;
+    }
+
+    public long getTotalCount() {
+        return totalCount;
+    }
+
+    public void setTotalCount(long totalCount) {
+        this.totalCount = totalCount;
+    }
+
+    public long getPageCount() {
+        return pageCount;
+    }
+
+    public void setPageCount(long pageCount) {
+        this.pageCount = pageCount;
+    }
+
+    public long getPageNumber() {
+        return pageNumber;
+    }
+
+    public void setPageNumber(long pageNumber) {
+        this.pageNumber = pageNumber;
+    }
+
+    public long getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(long pageSize) {
+        this.pageSize = pageSize;
+    }
+}

+ 11 - 0
data-mybatis-plus/src/main/java/com/qmth/boot/mybatis/query/BaseQuery.java

@@ -1,6 +1,7 @@
 package com.qmth.boot.mybatis.query;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.boot.core.collection.PageResult;
 
 /**
  * 分页排序查询基类,默认分页20条
@@ -34,4 +35,14 @@ public class BaseQuery<T> extends Page<T> {
     public long getPageSize() {
         return getSize();
     }
+
+    public PageResult<T> toPageResult() {
+        PageResult<T> result = new PageResult<>();
+        result.setResult(getRecords());
+        result.setPageNumber(getPageNumber());
+        result.setPageSize(getPageSize());
+        result.setTotalCount(getTotal());
+        result.setPageCount(getPages());
+        return result;
+    }
 }