Browse Source

TableInfo

miemie 5 years ago
parent
commit
25a39d4050

+ 2 - 0
mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/FieldStrategy.java

@@ -17,6 +17,8 @@ package com.baomidou.mybatisplus.annotation;
 
 /**
  * 字段策略枚举类
+ * <p>
+ * 如果字段是基本数据类型则最终效果等同于 {@link #IGNORED}
  *
  * @author hubin
  * @since 2016-09-09

+ 9 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableFieldInfo.java

@@ -64,6 +64,12 @@ public class TableFieldInfo implements Constants {
      * 属性类型
      */
     private final Class<?> propertyType;
+    /**
+     * 是否是基本数据类型
+     *
+     * @since 3.3.3 @2020-6-19
+     */
+    private final boolean isPrimitive;
     /**
      * 属性是否是 CharSequence 类型
      */
@@ -159,6 +165,7 @@ public class TableFieldInfo implements Constants {
         this.version = field.getAnnotation(Version.class) != null;
         this.property = field.getName();
         this.propertyType = reflector.getGetterType(this.property);
+        this.isPrimitive = this.propertyType.isPrimitive();
         this.isCharSequence = StringUtils.isCharSequence(this.propertyType);
         this.fieldFill = tableField.fill();
         this.withInsertFill = this.fieldFill == FieldFill.INSERT || this.fieldFill == FieldFill.INSERT_UPDATE;
@@ -241,6 +248,7 @@ public class TableFieldInfo implements Constants {
         this.version = field.getAnnotation(Version.class) != null;
         this.property = field.getName();
         this.propertyType = reflector.getGetterType(this.property);
+        this.isPrimitive = this.propertyType.isPrimitive();
         this.isCharSequence = StringUtils.isCharSequence(this.propertyType);
         this.el = this.property;
         this.insertStrategy = dbConfig.getInsertStrategy();
@@ -477,7 +485,7 @@ public class TableFieldInfo implements Constants {
         if (fieldStrategy == FieldStrategy.NEVER) {
             return null;
         }
-        if (fieldStrategy == FieldStrategy.IGNORED) {
+        if (isPrimitive || fieldStrategy == FieldStrategy.IGNORED) {
             return sqlScript;
         }
         if (fieldStrategy == FieldStrategy.NOT_EMPTY && isCharSequence) {

+ 12 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfoHelper.java

@@ -349,10 +349,15 @@ public class TableInfoHelper {
                 column = column.toUpperCase();
             }
         }
+        final Class<?> keyType = reflector.getGetterType(property);
+        if (keyType.isPrimitive()) {
+            logger.warn(String.format("This primary key of \"%s\" is primitive !不建议如此请使用包装类 in Class: \"%s\"",
+                property, tableInfo.getEntityType().getName()));
+        }
         tableInfo.setKeyRelated(checkRelated(underCamel, property, column))
             .setKeyColumn(column)
             .setKeyProperty(property)
-            .setKeyType(reflector.getGetterType(property));
+            .setKeyType(keyType);
     }
 
     /**
@@ -377,11 +382,16 @@ public class TableInfoHelper {
             if (dbConfig.isCapitalMode()) {
                 column = column.toUpperCase();
             }
+            final Class<?> keyType = reflector.getGetterType(property);
+            if (keyType.isPrimitive()) {
+                logger.warn(String.format("This primary key of \"%s\" is primitive !不建议如此请使用包装类 in Class: \"%s\"",
+                    property, tableInfo.getEntityType().getName()));
+            }
             tableInfo.setKeyRelated(checkRelated(tableInfo.isUnderCamel(), property, column))
                 .setIdType(dbConfig.getIdType())
                 .setKeyColumn(column)
                 .setKeyProperty(property)
-                .setKeyType(reflector.getGetterType(property));
+                .setKeyType(keyType);
             return true;
         }
         return false;