Browse Source

ipage 新增功能,泛型转换

miemie 6 years ago
parent
commit
35a266df33

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

@@ -18,6 +18,9 @@ package com.baomidou.mybatisplus.core.metadata;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
+
+import static java.util.stream.Collectors.toList;
 
 /**
  * <p>
@@ -178,4 +181,19 @@ public interface IPage<T> extends Serializable {
      * </p>
      */
     IPage<T> setCurrent(long current);
+
+    /**
+     * <p>
+     * IPage 的泛型转换
+     * </p>
+     *
+     * @param mapper 转换函数
+     * @param <R>    转换后的泛型
+     * @return 转换泛型后的 IPage
+     */
+    @SuppressWarnings("unchecked")
+    default <R> IPage<R> convert(Function<? super T, ? extends R> mapper) {
+        List<R> collect = this.getRecords().stream().map(mapper).collect(toList());
+        return ((IPage<R>) this).setRecords(collect);
+    }
 }

+ 2 - 2
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/EncryptTest.java

@@ -33,9 +33,9 @@ public class EncryptTest {
     public void testTableInfoHelper() {
         TableInfo info = TableInfoHelper.initTableInfo(null, Xx.class);
         System.out.println("----------- AllInsertSqlColumn -----------");
-        System.out.println(info.getAllInsertSqlColumn());
+        System.out.println(info.getAllInsertSqlColumn(false));
         System.out.println("----------- AllInsertSqlProperty -----------");
-        System.out.println(info.getAllInsertSqlProperty());
+        System.out.println(info.getAllInsertSqlProperty(false, null));
         System.out.println("----------- AllSqlSet -----------");
         System.out.println(info.getAllSqlSet(true, "ew.entity."));
         System.out.println("----------- AllSqlWhere -----------");