Bladeren bron

还原原来的测试用例,构建新的测试用例

唐振超 2 jaren geleden
bovenliggende
commit
b754eabdb8

+ 53 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfoHelper.java

@@ -303,13 +303,13 @@ public class TableInfoHelper {
         AnnotationHandler annotationHandler = globalConfig.getAnnotationHandler();
         PostInitTableInfoHandler postInitTableInfoHandler = globalConfig.getPostInitTableInfoHandler();
         Reflector reflector = tableInfo.getReflector();
-        List<Field> list = getAllFields(clazz);
+        List<Field> list = getAllFields(clazz, annotationHandler);
         // 标记是否读取到主键
         boolean isReadPK = false;
         // 是否存在 @TableId 注解
-        boolean existTableId = isExistTableId(clazz, list);
+        boolean existTableId = isExistTableId(list, annotationHandler);
         // 是否存在 @TableLogic 注解
-        boolean existTableLogic = isExistTableLogic(clazz, list);
+        boolean existTableLogic = isExistTableLogic(list, annotationHandler);
 
         List<TableFieldInfo> fieldList = new ArrayList<>(list.size());
         for (Field field : list) {
@@ -379,6 +379,18 @@ public class TableInfoHelper {
     public static boolean isExistTableId(Class<?> clazz, List<Field> list) {
         TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
         AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(tableInfo.getConfiguration()).getAnnotationHandler();
+        return isExistTableId(list, annotationHandler);
+    }
+
+    /**
+     * <p>
+     * 判断主键注解是否存在
+     * </p>
+     *
+     * @param list 字段列表
+     * @return true 为存在 {@link TableId} 注解;
+     */
+    public static boolean isExistTableId(List<Field> list, AnnotationHandler annotationHandler) {
         return list.stream().anyMatch(field -> annotationHandler.isAnnotationPresent(field, TableId.class));
     }
 
@@ -394,6 +406,18 @@ public class TableInfoHelper {
     public static boolean isExistTableLogic(Class<?> clazz, List<Field> list) {
         TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
         AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(tableInfo.getConfiguration()).getAnnotationHandler();
+        return isExistTableLogic(list, annotationHandler);
+    }
+
+    /**
+     * <p>
+     * 判断逻辑删除注解是否存在
+     * </p>
+     *
+     * @param list 字段列表
+     * @return true 为存在 {@link TableLogic} 注解;
+     */
+    public static boolean isExistTableLogic(List<Field> list, AnnotationHandler annotationHandler) {
         return list.stream().anyMatch(field -> annotationHandler.isAnnotationPresent(field, TableLogic.class));
     }
 
@@ -409,6 +433,19 @@ public class TableInfoHelper {
     public static boolean isExistOrderBy(Class<?> clazz, List<Field> list) {
         TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
         AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(tableInfo.getConfiguration()).getAnnotationHandler();
+        return isExistOrderBy(list, annotationHandler);
+    }
+
+    /**
+     * <p>
+     * 判断排序注解是否存在
+     * </p>
+     *
+     * @param list 字段列表
+     * @param annotationHandler 注解处理类
+     * @return true 为存在 {@link OrderBy} 注解;
+     */
+    public static boolean isExistOrderBy(List<Field> list, AnnotationHandler annotationHandler) {
         return list.stream().anyMatch(field -> annotationHandler.isAnnotationPresent(field, OrderBy.class));
     }
 
@@ -545,6 +582,19 @@ public class TableInfoHelper {
     public static List<Field> getAllFields(Class<?> clazz) {
         TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
         AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(tableInfo.getConfiguration()).getAnnotationHandler();
+        return getAllFields(clazz, annotationHandler);
+    }
+
+    /**
+     * <p>
+     * 获取该类的所有属性列表
+     * </p>
+     *
+     * @param clazz             反射类
+     * @param annotationHandler 注解处理类
+     * @return 属性集合
+     */
+    public static List<Field> getAllFields(Class<?> clazz, AnnotationHandler annotationHandler) {
         List<Field> fieldList = ReflectionKit.getFieldList(ClassUtils.getUserClass(clazz));
         return fieldList.stream()
             .filter(field -> {

+ 1 - 1
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/Entity.java

@@ -198,7 +198,7 @@ public class Entity implements ITemplate {
     public void convertSuperEntityColumns(Class<?> clazz) {
         com.baomidou.mybatisplus.core.metadata.TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
         AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(tableInfo.getConfiguration()).getAnnotationHandler();
-        List<Field> fields = TableInfoHelper.getAllFields(clazz);
+        List<Field> fields = TableInfoHelper.getAllFields(clazz, annotationHandler);
         this.superEntityColumns.addAll(fields.stream().map(field -> {
             TableId tableId = annotationHandler.getAnnotation(field, TableId.class);
             if (tableId != null && StringUtils.isNotBlank(tableId.value())) {

+ 40 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/CustomFillTest.java

@@ -0,0 +1,40 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.test.h2.customfill.mapper.TestModelMapper;
+import com.baomidou.mybatisplus.test.h2.customfill.model.TestModel;
+import org.apache.ibatis.builder.MapperBuilderAssistant;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.annotation.Resource;
+
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+@ExtendWith(SpringExtension.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-custom-fill-test-h2.xml"})
+public class CustomFillTest {
+
+    @Resource
+    private TestModelMapper testModelMapper;
+
+    @BeforeAll
+    public static void before(){
+        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), TestModel.class);
+    }
+
+    @Test
+    public void testInsert() {
+
+        TestModel testModel = new TestModel();
+        testModelMapper.insert(testModel);
+        Assertions.assertNotNull(testModel.getA());
+        Assertions.assertNotNull(testModel.getB());
+    }
+}

+ 0 - 8
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/FillPerformanceTest.java

@@ -1,6 +1,5 @@
 package com.baomidou.mybatisplus.test.h2;
 
-import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.test.h2.fillperformance.model.PerformanceModel;
 import com.baomidou.mybatisplus.test.h2.fillperformance.service.IPerformanceModelService;
 import org.junit.jupiter.api.MethodOrderer;
@@ -35,11 +34,4 @@ class FillPerformanceTest {
         System.out.println(end - start);
         System.out.println("-------------------------");
     }
-
-    @Test
-    void testCustomAnnotation(){
-        PerformanceModel performanceModel = new PerformanceModel();
-        performanceModelService.save(performanceModel);
-        Assert.notEmpty(performanceModel.getA(), "自定义注解获取方式测试失败");
-    }
 }

+ 0 - 217
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2AnnotationHandler.java

@@ -1,217 +0,0 @@
-package com.baomidou.mybatisplus.test.h2;
-
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.FieldStrategy;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.core.handlers.AnnotationHandler;
-import com.baomidou.mybatisplus.test.h2.fillperformance.annotation.InsertUpdateFill;
-import com.baomidou.mybatisplus.test.h2.fillperformance.model.PerformanceModel;
-import org.apache.ibatis.type.JdbcType;
-import org.apache.ibatis.type.TypeHandler;
-import org.apache.ibatis.type.UnknownTypeHandler;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-
-
-public class H2AnnotationHandler implements AnnotationHandler {
-
-    /**
-     * 结合{@link PerformanceModel#getA()}简单实现{@link com.baomidou.mybatisplus.test.h2.fillperformance.annotation.InsertUpdateFill} 的获取过程
-     *
-     * @param field           字段
-     * @param annotationClass 要获取的注解class
-     * @param <T>
-     * @return
-     */
-    @Override
-    public <T extends Annotation> T getAnnotation(Field field, Class<T> annotationClass) {
-
-        T annotation = field.getAnnotation(annotationClass);
-        if (annotationClass != TableField.class) {
-            return annotation;
-        }
-
-        Annotation insertUpdateFillAnno = field.getAnnotation(InsertUpdateFill.class);
-        if (insertUpdateFillAnno == null) {
-            return annotation;
-        }
-
-        /*
-         如果是要获取TableField场景,尝试判断是否存在InsertUpdateFill,存在则假定存在@TableField(fill = FieldFill.INSERT_UPDATE)的配置,
-         实际应用场景,应采取更加通用的方式,例如Spring的AnnotationUtils等
-         */
-        if (annotation != null) {
-            TableField finalAnnotation = (TableField) annotation;
-            annotation = (T) new TableField() {
-                @Override
-                public Class<? extends Annotation> annotationType() {
-                    return finalAnnotation.annotationType();
-                }
-
-                @Override
-                public String value() {
-                    return finalAnnotation.value();
-                }
-
-                @Override
-                public boolean exist() {
-                    return finalAnnotation.exist();
-                }
-
-                @Override
-                public String condition() {
-                    return finalAnnotation.value();
-                }
-
-                @Override
-                public String update() {
-                    return finalAnnotation.update();
-                }
-
-                @Override
-                public FieldStrategy insertStrategy() {
-                    return finalAnnotation.insertStrategy();
-                }
-
-                @Override
-                public FieldStrategy updateStrategy() {
-                    return finalAnnotation.updateStrategy();
-                }
-
-                @Override
-                public FieldStrategy whereStrategy() {
-                    return finalAnnotation.whereStrategy();
-                }
-
-                @Override
-                public FieldFill fill() {
-                    return FieldFill.INSERT_UPDATE;
-                }
-
-                @Override
-                public boolean select() {
-                    return finalAnnotation.select();
-                }
-
-                @Override
-                public boolean keepGlobalFormat() {
-                    return finalAnnotation.keepGlobalFormat();
-                }
-
-                @Override
-                public String property() {
-                    return finalAnnotation.value();
-                }
-
-                @Override
-                public JdbcType jdbcType() {
-                    return finalAnnotation.jdbcType();
-                }
-
-                @Override
-                public Class<? extends TypeHandler> typeHandler() {
-                    return finalAnnotation.typeHandler();
-                }
-
-                @Override
-                public boolean javaType() {
-                    return finalAnnotation.javaType();
-                }
-
-                @Override
-                public String numericScale() {
-                    return finalAnnotation.value();
-                }
-            };
-        } else {
-            annotation = (T) new TableField() {
-                @Override
-                public Class<? extends Annotation> annotationType() {
-                    return TableField.class;
-                }
-
-                @Override
-                public String value() {
-                    return "";
-                }
-
-                @Override
-                public boolean exist() {
-                    return true;
-                }
-
-                @Override
-                public String condition() {
-                    return "";
-                }
-
-                @Override
-                public String update() {
-                    return "";
-                }
-
-                @Override
-                public FieldStrategy insertStrategy() {
-                    return FieldStrategy.DEFAULT;
-                }
-
-                @Override
-                public FieldStrategy updateStrategy() {
-                    return FieldStrategy.DEFAULT;
-                }
-
-                @Override
-                public FieldStrategy whereStrategy() {
-                    return FieldStrategy.DEFAULT;
-                }
-
-                @Override
-                public FieldFill fill() {
-                    return FieldFill.INSERT_UPDATE;
-                }
-
-                @Override
-                public boolean select() {
-                    return true;
-                }
-
-                @Override
-                public boolean keepGlobalFormat() {
-                    return false;
-                }
-
-                @Override
-                public String property() {
-                    return "";
-                }
-
-                @Override
-                public JdbcType jdbcType() {
-                    return JdbcType.UNDEFINED;
-                }
-
-                @Override
-                public Class<? extends TypeHandler> typeHandler() {
-                    return UnknownTypeHandler.class;
-                }
-
-                @Override
-                public boolean javaType() {
-                    return false;
-                }
-
-                @Override
-                public String numericScale() {
-                    return "";
-                }
-            };
-        }
-        return annotation;
-    }
-
-    @Override
-    public <T extends Annotation> boolean isAnnotationPresent(Field field, Class<T> annotationClass) {
-        return getAnnotation(field, annotationClass) != null;
-    }
-}

+ 0 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfig.java

@@ -28,7 +28,6 @@ import com.baomidou.mybatisplus.extension.plugins.inner.DataChangeRecorderInnerI
 import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
-import com.baomidou.mybatisplus.test.h2.H2AnnotationHandler;
 import com.baomidou.mybatisplus.test.h2.H2MetaObjectHandler;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -74,7 +73,6 @@ public class MybatisPlusConfig {
         sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
 
         globalConfig.setMetaObjectHandler(new H2MetaObjectHandler());
-        globalConfig.setAnnotationHandler(new H2AnnotationHandler());
         globalConfig.setSqlInjector(new DefaultSqlInjector() {
 
             /**

+ 296 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/customfill/CustomFillConfig.java

@@ -0,0 +1,296 @@
+package com.baomidou.mybatisplus.test.h2.customfill;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.core.config.GlobalConfig;
+import com.baomidou.mybatisplus.core.handlers.AnnotationHandler;
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
+import com.baomidou.mybatisplus.test.h2.customfill.annotation.InsertUpdateFill;
+import org.apache.ibatis.reflection.MetaObject;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.type.EnumOrdinalTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.TypeHandler;
+import org.apache.ibatis.type.UnknownTypeHandler;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Configuration
+@MapperScan("com.baomidou.mybatisplus.test.h2.customfill.mapper")
+public class CustomFillConfig {
+
+    @Bean
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
+        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+        sqlSessionFactory.setDataSource(dataSource);
+        MybatisConfiguration configuration = new MybatisConfiguration();
+        configuration.setJdbcTypeForNull(JdbcType.NULL);
+        configuration.setMapUnderscoreToCamelCase(true);
+        configuration.setDefaultExecutorType(ExecutorType.REUSE);
+        configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
+        sqlSessionFactory.setConfiguration(configuration);
+        GlobalConfig globalConfig = new GlobalConfig();
+        globalConfig.setMetaObjectHandler(metaObjectHandler());
+        globalConfig.setAnnotationHandler(annotationHandler());
+        sqlSessionFactory.setGlobalConfig(globalConfig);
+
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
+
+        return sqlSessionFactory.getObject();
+    }
+
+    @Bean
+    public MetaObjectHandler metaObjectHandler() {
+        return new MetaObjectHandler() {
+            @Override
+            public void insertFill(MetaObject metaObject) {
+                Object object = metaObject.getOriginalObject();
+                Class<?> clazz = object.getClass();
+
+                Field[] declaredFields = clazz.getDeclaredFields();
+                List<Field> fieldList = Arrays.stream(declaredFields)
+                    .filter(field -> metaObject.hasSetter(field.getName()))
+                    .filter(field -> {
+                        AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(TableInfoHelper.getTableInfo(clazz).getConfiguration()).getAnnotationHandler();
+                        return annotationHandler.isAnnotationPresent(field, TableField.class);
+                    })
+                    .collect(Collectors.toList());
+
+                for (Field field : fieldList) {
+                    // 此处没有做字段与列的自动转化
+                    String columnName = field.getName();
+                    setFieldValByName(columnName, "1234567890", metaObject);
+                }
+            }
+
+            @Override
+            public void updateFill(MetaObject metaObject) {
+
+            }
+        };
+    }
+    
+    @Bean
+    public AnnotationHandler annotationHandler() {
+        return new AnnotationHandler() {
+
+            /**
+             * 结合{@link com.baomidou.mybatisplus.test.h2.customfill.model.TestModel#getA()}简单实现{@link InsertUpdateFill} 的获取过程
+             *
+             * @param field           字段
+             * @param annotationClass 要获取的注解class
+             * @param <T>
+             * @return
+             */
+            @Override
+            public <T extends Annotation > T getAnnotation(Field field, Class<T> annotationClass) {
+
+                T annotation = field.getAnnotation(annotationClass);
+                if (annotationClass != TableField.class) {
+                    return annotation;
+                }
+
+                Annotation insertUpdateFillAnno = field.getAnnotation(InsertUpdateFill.class);
+                if (insertUpdateFillAnno == null) {
+                    return annotation;
+                }
+
+        /*
+         如果是要获取TableField场景,尝试判断是否存在InsertUpdateFill,存在则假定存在@TableField(fill = FieldFill.INSERT_UPDATE)的配置,
+         实际应用场景,应采取更加通用的方式,例如Spring的AnnotationUtils等
+         */
+                if (annotation != null) {
+                    TableField finalAnnotation = (TableField) annotation;
+                    annotation = (T) new TableField() {
+                        @Override
+                        public Class<? extends Annotation> annotationType() {
+                            return finalAnnotation.annotationType();
+                        }
+
+                        @Override
+                        public String value() {
+                            return finalAnnotation.value();
+                        }
+
+                        @Override
+                        public boolean exist() {
+                            return finalAnnotation.exist();
+                        }
+
+                        @Override
+                        public String condition() {
+                            return finalAnnotation.value();
+                        }
+
+                        @Override
+                        public String update() {
+                            return finalAnnotation.update();
+                        }
+
+                        @Override
+                        public FieldStrategy insertStrategy() {
+                            return finalAnnotation.insertStrategy();
+                        }
+
+                        @Override
+                        public FieldStrategy updateStrategy() {
+                            return finalAnnotation.updateStrategy();
+                        }
+
+                        @Override
+                        public FieldStrategy whereStrategy() {
+                            return finalAnnotation.whereStrategy();
+                        }
+
+                        @Override
+                        public FieldFill fill() {
+                            return FieldFill.INSERT_UPDATE;
+                        }
+
+                        @Override
+                        public boolean select() {
+                            return finalAnnotation.select();
+                        }
+
+                        @Override
+                        public boolean keepGlobalFormat() {
+                            return finalAnnotation.keepGlobalFormat();
+                        }
+
+                        @Override
+                        public String property() {
+                            return finalAnnotation.value();
+                        }
+
+                        @Override
+                        public JdbcType jdbcType() {
+                            return finalAnnotation.jdbcType();
+                        }
+
+                        @Override
+                        public Class<? extends TypeHandler> typeHandler() {
+                            return finalAnnotation.typeHandler();
+                        }
+
+                        @Override
+                        public boolean javaType() {
+                            return finalAnnotation.javaType();
+                        }
+
+                        @Override
+                        public String numericScale() {
+                            return finalAnnotation.value();
+                        }
+                    };
+                } else {
+                    annotation = (T) new TableField() {
+                        @Override
+                        public Class<? extends Annotation> annotationType() {
+                            return TableField.class;
+                        }
+
+                        @Override
+                        public String value() {
+                            return "";
+                        }
+
+                        @Override
+                        public boolean exist() {
+                            return true;
+                        }
+
+                        @Override
+                        public String condition() {
+                            return "";
+                        }
+
+                        @Override
+                        public String update() {
+                            return "";
+                        }
+
+                        @Override
+                        public FieldStrategy insertStrategy() {
+                            return FieldStrategy.DEFAULT;
+                        }
+
+                        @Override
+                        public FieldStrategy updateStrategy() {
+                            return FieldStrategy.DEFAULT;
+                        }
+
+                        @Override
+                        public FieldStrategy whereStrategy() {
+                            return FieldStrategy.DEFAULT;
+                        }
+
+                        @Override
+                        public FieldFill fill() {
+                            return FieldFill.INSERT_UPDATE;
+                        }
+
+                        @Override
+                        public boolean select() {
+                            return true;
+                        }
+
+                        @Override
+                        public boolean keepGlobalFormat() {
+                            return false;
+                        }
+
+                        @Override
+                        public String property() {
+                            return "";
+                        }
+
+                        @Override
+                        public JdbcType jdbcType() {
+                            return JdbcType.UNDEFINED;
+                        }
+
+                        @Override
+                        public Class<? extends TypeHandler> typeHandler() {
+                            return UnknownTypeHandler.class;
+                        }
+
+                        @Override
+                        public boolean javaType() {
+                            return false;
+                        }
+
+                        @Override
+                        public String numericScale() {
+                            return "";
+                        }
+                    };
+                }
+                return annotation;
+            }
+
+            @Override
+            public <T extends Annotation> boolean isAnnotationPresent(Field field, Class<T> annotationClass) {
+                return getAnnotation(field, annotationClass) != null;
+            }
+        };
+    }
+
+}

+ 6 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/fillperformance/annotation/InsertUpdateFill.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/customfill/annotation/InsertUpdateFill.java

@@ -1,9 +1,13 @@
-package com.baomidou.mybatisplus.test.h2.fillperformance.annotation;
+package com.baomidou.mybatisplus.test.h2.customfill.annotation;
 
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 
-import java.lang.annotation.*;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 
 @Documented
 @Retention(RetentionPolicy.RUNTIME)

+ 8 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/customfill/mapper/TestModelMapper.java

@@ -0,0 +1,8 @@
+package com.baomidou.mybatisplus.test.h2.customfill.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.customfill.model.TestModel;
+
+public interface TestModelMapper extends BaseMapper<TestModel> {
+
+}

+ 18 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/customfill/model/TestModel.java

@@ -0,0 +1,18 @@
+package com.baomidou.mybatisplus.test.h2.customfill.model;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.test.h2.customfill.annotation.InsertUpdateFill;
+import lombok.Data;
+
+@Data
+@TableName(value = "t_fill_test")
+public class TestModel {
+
+    private Long id;
+    @InsertUpdateFill
+    private String a;
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private String b;
+}

+ 10 - 36
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/fillperformance/FillPerformanceConfig.java

@@ -1,12 +1,8 @@
 package com.baomidou.mybatisplus.test.h2.fillperformance;
 
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
-import com.baomidou.mybatisplus.core.handlers.AnnotationHandler;
 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
-import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
-import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
@@ -20,10 +16,6 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 import javax.sql.DataSource;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
 
 @Configuration
 @MapperScan("com.baomidou.mybatisplus.test.h2.fillperformance.mapper")
@@ -53,19 +45,6 @@ public class FillPerformanceConfig {
         return new MetaObjectHandler() {
             @Override
             public void insertFill(MetaObject metaObject) {
-
-                Object object = metaObject.getOriginalObject();
-                Class<?> clazz = object.getClass();
-
-                Field[] declaredFields = clazz.getDeclaredFields();
-                List<Field> fieldList = Arrays.stream(declaredFields)
-                    .filter(field -> metaObject.hasSetter(field.getName()))
-                    .filter(field -> {
-                        AnnotationHandler annotationHandler = GlobalConfigUtils.getGlobalConfig(TableInfoHelper.getTableInfo(clazz).getConfiguration()).getAnnotationHandler();
-                        return annotationHandler.isAnnotationPresent(field, TableField.class);
-                    })
-                    .collect(Collectors.toList());
-
 //                strictInsertFill(metaObject,"c",String.class,"1234567890");
 //                strictInsertFill(metaObject,"d",String.class,"1234567890");
 //                strictInsertFill(metaObject,"e",String.class,"1234567890");
@@ -76,21 +55,16 @@ public class FillPerformanceConfig {
 //                strictInsertFill(metaObject,"j",String.class,"1234567890");
 //                strictInsertFill(metaObject,"l",String.class,"1234567890");
 //                strictInsertFill(metaObject,"m",String.class,"1234567890");
-                for (Field field : fieldList) {
-                    // 此处没有做字段与列的自动转化
-                    String columnName = field.getName();
-                    setFieldValByName(columnName, "1234567890", metaObject);
-                }
-                // setFieldValByName("c", "1234567890", metaObject);
-                // setFieldValByName("d", "1234567890", metaObject);
-                // setFieldValByName("e", "1234567890", metaObject);
-                // setFieldValByName("f", "1234567890", metaObject);
-                // setFieldValByName("g", "1234567890", metaObject);
-                // setFieldValByName("h", "1234567890", metaObject);
-                // setFieldValByName("i", "1234567890", metaObject);
-                // setFieldValByName("j", "1234567890", metaObject);
-                // setFieldValByName("l", "1234567890", metaObject);
-                // setFieldValByName("m", "1234567890", metaObject);
+                setFieldValByName("c", "1234567890", metaObject);
+                setFieldValByName("d", "1234567890", metaObject);
+                setFieldValByName("e", "1234567890", metaObject);
+                setFieldValByName("f", "1234567890", metaObject);
+                setFieldValByName("g", "1234567890", metaObject);
+                setFieldValByName("h", "1234567890", metaObject);
+                setFieldValByName("i", "1234567890", metaObject);
+                setFieldValByName("j", "1234567890", metaObject);
+                setFieldValByName("l", "1234567890", metaObject);
+                setFieldValByName("m", "1234567890", metaObject);
 //                setInsertFieldValByName("c","1234567890",metaObject);
 //                setInsertFieldValByName("d","1234567890",metaObject);
 //                setInsertFieldValByName("e","1234567890",metaObject);

+ 0 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/fillperformance/model/PerformanceModel.java

@@ -3,15 +3,11 @@ package com.baomidou.mybatisplus.test.h2.fillperformance.model;
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.test.h2.fillperformance.annotation.InsertUpdateFill;
-import lombok.Data;
 
-@Data
 @TableName(value = "t_fill_performance")
 public class PerformanceModel {
 
     private Long id;
-    @InsertUpdateFill
     private String a;
     private String b;
     @TableField(fill = FieldFill.INSERT_UPDATE)

+ 6 - 0
mybatis-plus/src/test/resources/customfilltest/init.ddl.sql

@@ -0,0 +1,6 @@
+CREATE TABLE IF NOT EXISTS  t_fill_test (
+	id BIGINT(20) NOT NULL,
+	a VARCHAR(30) NULL DEFAULT NULL ,
+	b VARCHAR(30) NULL DEFAULT NULL ,
+	PRIMARY KEY (id)
+);

+ 14 - 0
mybatis-plus/src/test/resources/h2/spring-custom-fill-test-h2.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns="http://www.springframework.org/schema/beans"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+    <context:component-scan base-package="com.baomidou.mybatisplus.test.h2.customfill"/>
+
+    <bean class="com.baomidou.mybatisplus.test.h2.config.DBConfig">
+        <property name="locationPattern" value="classpath:/customfilltest/*.sql"/>
+    </bean>
+
+</beans>