miemie пре 6 година
родитељ
комит
2afdd0bc44

+ 6 - 9
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/TableInfoHelper.java

@@ -466,15 +466,12 @@ public class TableInfoHelper {
     public static List<Field> getAllFields(Class<?> clazz) {
         List<Field> fieldList = ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz));
         if (CollectionUtils.isNotEmpty(fieldList)) {
-            Iterator<Field> iterator = fieldList.iterator();
-            while (iterator.hasNext()) {
-                Field field = iterator.next();
-                /* 过滤注解非表字段属性 */
-                TableField tableField = field.getAnnotation(TableField.class);
-                if (tableField != null && !tableField.exist()) {
-                    iterator.remove();
-                }
-            }
+            return fieldList.stream()
+                .filter(i -> {
+                    /* 过滤注解非表字段属性 */
+                    TableField tableField = i.getAnnotation(TableField.class);
+                    return (tableField == null || tableField.exist());
+                }).collect(toList());
         }
         return fieldList;
     }

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

@@ -1,7 +1,10 @@
 package com.baomidou.mybatisplus.core.test;
 
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
 import com.baomidou.mybatisplus.core.toolkit.EncryptUtils;
 import com.baomidou.mybatisplus.core.toolkit.TableInfoHelper;
+import lombok.Data;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -20,4 +23,20 @@ public class EncryptTest {
     public void other() {
         System.out.println(TableInfoHelper.checkRelated(true, "order", "'order'"));
     }
+
+    @Test
+    public void testTableInfoHelper() {
+        TableInfo tableInfo = TableInfoHelper.initTableInfo(null, Xx.class);
+        System.out.println(tableInfo);
+    }
+
+    @Data
+    public static class Xx {
+        @TableField(exist = false)
+        private String x1;
+        private String x2;
+        private String x3;
+        private String x4;
+        private String x5;
+    }
 }