Selaa lähdekoodia

信息[字段是否是乐观锁字段]加入 TableFieldInfo

miemie 6 vuotta sitten
vanhempi
commit
7f28467f15

+ 6 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableFieldInfo.java

@@ -78,6 +78,10 @@ public class TableFieldInfo implements Constants {
      * <p>大字段可设置为 false 不加入 select 查询范围</p>
      */
     private boolean select = true;
+    /**
+     * 是否是乐观锁字段
+     */
+    private boolean version;
     /**
      * 逻辑删除值
      */
@@ -109,6 +113,7 @@ public class TableFieldInfo implements Constants {
      */
     public TableFieldInfo(GlobalConfig.DbConfig dbConfig, TableInfo tableInfo, Field field,
                           String column, String el, TableField tableField) {
+        this.version = field.getAnnotation(Version.class) != null;
         this.property = field.getName();
         this.propertyType = field.getType();
         this.isCharSequence = StringUtils.isCharSequence(this.propertyType);
@@ -151,6 +156,7 @@ public class TableFieldInfo implements Constants {
      * 不存在 TableField 注解时, 使用的构造函数
      */
     public TableFieldInfo(GlobalConfig.DbConfig dbConfig, TableInfo tableInfo, Field field) {
+        this.version = field.getAnnotation(Version.class) != null;
         this.property = field.getName();
         this.propertyType = field.getType();
         this.isCharSequence = StringUtils.isCharSequence(this.propertyType);

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

@@ -96,8 +96,8 @@ public class MybatisPlusConfig {
                 methodList.add(new InsertBatchSomeColumn()
                     // 不要逻辑删除字段
                     .addPredicate(t -> !t.isLogicDelete())
-                    // 不要字段名是 version 的字段
-                    .addPredicate(t -> !t.getProperty().equals("version"))
+                    // 不要乐观锁字段
+                    .addPredicate(t -> !t.isVersion())
                     // 不要填充策略是 UPDATE 的字段
                     .addPredicate(t -> t.getFieldFill() != FieldFill.UPDATE));
                 methodList.add(new AlwaysUpdateSomeColumnById()