Prechádzať zdrojové kódy

TableField.java 移除属性 typeHandlerStr

miemie 5 rokov pred
rodič
commit
1aa9d77a28

+ 2 - 11
mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/TableField.java

@@ -123,22 +123,13 @@ public @interface TableField {
     JdbcType jdbcType() default JdbcType.UNDEFINED;
 
     /**
-     * 类型处理器 (该默认值不代表会按照该值生效)(和下面的都配置情况下,这个优先)
+     * 类型处理器 (该默认值不代表会按照该值生效)
      * <p>
      * {@link ResultMapping#typeHandler} and {@link ParameterMapping#typeHandler}
      *
      * @since 3.1.2
      */
-    Class<? extends TypeHandler<?>> typeHandler() default UnknownTypeHandler.class;
-
-    /**
-     * 类型处理器 (该默认值不代表会按照该值生效)(和上面的都配置情况下,上面的优先)
-     * <p>
-     * {@link ResultMapping#typeHandler} and {@link ParameterMapping#typeHandler}
-     *
-     * @since 3.1.2
-     */
-    String typeHandlerStr() default "";
+    Class<? extends TypeHandler> typeHandler() default UnknownTypeHandler.class;
 
     /**
      * 指定小数点后保留的位数

+ 3 - 7
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableFieldInfo.java

@@ -19,7 +19,6 @@ import com.baomidou.mybatisplus.annotation.*;
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
 import lombok.AccessLevel;
@@ -141,6 +140,7 @@ public class TableFieldInfo implements Constants {
     /**
      * 全新的 存在 TableField 注解时使用的构造函数
      */
+    @SuppressWarnings("unchecked")
     public TableFieldInfo(GlobalConfig.DbConfig dbConfig, TableInfo tableInfo, Field field, TableField tableField) {
         this.version = field.getAnnotation(Version.class) != null;
         this.property = field.getName();
@@ -149,8 +149,7 @@ public class TableFieldInfo implements Constants {
         this.fieldFill = tableField.fill();
         this.update = tableField.update();
         JdbcType jdbcType = tableField.jdbcType();
-        final Class<? extends TypeHandler<?>> typeHandler = tableField.typeHandler();
-        final String handlerStr = tableField.typeHandlerStr();
+        final Class<? extends TypeHandler> typeHandler = tableField.typeHandler();
         final String numericScale = tableField.numericScale();
         String el = this.property;
         if (JdbcType.UNDEFINED != jdbcType) {
@@ -158,11 +157,8 @@ public class TableFieldInfo implements Constants {
             el += (COMMA + "jdbcType=" + jdbcType.name());
         }
         if (UnknownTypeHandler.class != typeHandler) {
-            this.typeHandler = typeHandler;
+            this.typeHandler = (Class<? extends TypeHandler<?>>) typeHandler;
             el += (COMMA + "typeHandler=" + typeHandler.getName());
-        } else if (StringUtils.isNotEmpty(handlerStr)) {
-            this.typeHandler = ReflectionKit.getClass(handlerStr);
-            el += (COMMA + "typeHandler=" + this.typeHandler.getName());
         }
         if (StringUtils.isNotEmpty(numericScale)) {
             el += (COMMA + "numericScale=" + numericScale);

+ 2 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/entity/ResultMapEntity.java

@@ -17,6 +17,7 @@ package com.baomidou.mybatisplus.test.base.entity;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.test.base.type.JsonTypeHandler;
 import com.baomidou.mybatisplus.test.base.type.ListTypeHandler;
 import com.baomidou.mybatisplus.test.base.type.MapTypeHandler;
 import lombok.Data;
@@ -45,6 +46,6 @@ public class ResultMapEntity {
     private List<String> list;
     @TableField(typeHandler = MapTypeHandler.class)
     private Map<String, Object> map;
-    @TableField(typeHandlerStr = "com.baomidou.mybatisplus.test.base.type.JsonTypeHandler")
+    @TableField(typeHandler = JsonTypeHandler.class)
     private Map<String, Object> mapp;
 }