瀏覽代碼

添加mybatis-plus-extension对应的mapper方法支持自定义方法名功能

义陆无忧 5 年之前
父節點
當前提交
0cda1c473d

+ 10 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/AlwaysUpdateSomeColumnById.java

@@ -62,7 +62,7 @@ public class AlwaysUpdateSomeColumnById extends AbstractMethod {
 
 
     @Override
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
-        SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
+        sqlMethod = SqlMethod.UPDATE_BY_ID;
         final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, false);
         final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, false);
         String sqlSet = this.filterTableFieldInfo(tableInfo.getFieldList(), getPredicate(),
         String sqlSet = this.filterTableFieldInfo(tableInfo.getFieldList(), getPredicate(),
             i -> i.getSqlSet(true, ENTITY_DOT), NEWLINE);
             i -> i.getSqlSet(true, ENTITY_DOT), NEWLINE);
@@ -70,7 +70,7 @@ public class AlwaysUpdateSomeColumnById extends AbstractMethod {
         String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet,
         String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet,
             tableInfo.getKeyColumn(), ENTITY_DOT + tableInfo.getKeyProperty(), additional);
             tableInfo.getKeyColumn(), ENTITY_DOT + tableInfo.getKeyProperty(), additional);
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-        return addUpdateMappedStatement(mapperClass, modelClass, MAPPER_METHOD, sqlSource);
+        return addUpdateMappedStatement(mapperClass, modelClass, getMethod(), sqlSource);
     }
     }
 
 
     private Predicate<TableFieldInfo> getPredicate() {
     private Predicate<TableFieldInfo> getPredicate() {
@@ -80,4 +80,12 @@ public class AlwaysUpdateSomeColumnById extends AbstractMethod {
         }
         }
         return noLogic;
         return noLogic;
     }
     }
+
+    @Override
+    public String getMethod() {
+        if (method == null || method.isEmpty()) {
+            method = MAPPER_METHOD;
+        }
+        return method;
+    }
 }
 }

+ 9 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/InsertBatchSomeColumn.java

@@ -109,6 +109,14 @@ public class InsertBatchSomeColumn extends AbstractMethod {
         }
         }
         String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript);
         String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript);
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-        return this.addInsertMappedStatement(mapperClass, modelClass, MAPPER_METHOD, sqlSource, keyGenerator, keyProperty, keyColumn);
+        return this.addInsertMappedStatement(mapperClass, modelClass, getMethod(), sqlSource, keyGenerator, keyProperty, keyColumn);
+    }
+
+    @Override
+    public String getMethod() {
+        if (method == null || method.isEmpty()) {
+            method = MAPPER_METHOD;
+        }
+        return method;
     }
     }
 }
 }

+ 9 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/LogicDeleteByIdWithFill.java

@@ -73,6 +73,14 @@ public class LogicDeleteByIdWithFill extends AbstractMethod {
                 tableInfo.getKeyProperty());
                 tableInfo.getKeyProperty());
         }
         }
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-        return addUpdateMappedStatement(mapperClass, modelClass, MAPPER_METHOD, sqlSource);
+        return addUpdateMappedStatement(mapperClass, modelClass, getMethod(), sqlSource);
+    }
+
+    @Override
+    public String getMethod() {
+        if (method == null || method.isEmpty()) {
+            method = MAPPER_METHOD;
+        }
+        return method;
     }
     }
 }
 }