Bladeren bron

Merge pull request #3655 from nieqiurong/delete_batch_by_entity

deleteBatchIds支持传入实体(实现Serializable)删除.
qmdx 4 jaren geleden
bovenliggende
commit
e3dfc105cd

+ 8 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteBatchByIds.java

@@ -37,14 +37,20 @@ public class DeleteBatchByIds extends AbstractMethod {
         if (tableInfo.isWithLogicDelete()) {
             sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
                 tableInfo.getKeyColumn(),
-                SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA),
+                SqlScriptUtils.convertForeach(
+                    SqlScriptUtils.convertChoose("@com.baomidou.mybatisplus.core.toolkit.ReflectionKit@isPrimitiveOrWrapper(item.getClass())",
+                        "#{item}", "#{item." + tableInfo.getKeyProperty() + "}"),
+                    COLLECTION, null, "item", COMMA),
                 tableInfo.getLogicDeleteSql(true, true));
             SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
             return addUpdateMappedStatement(mapperClass, modelClass, getMethod(sqlMethod), sqlSource);
         } else {
             sqlMethod = SqlMethod.DELETE_BATCH_BY_IDS;
             sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(),
-                SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA));
+                SqlScriptUtils.convertForeach(
+                    SqlScriptUtils.convertChoose("@com.baomidou.mybatisplus.core.toolkit.ReflectionKit@isPrimitiveOrWrapper(item.getClass())",
+                        "#{item}", "#{item." + tableInfo.getKeyProperty() + "}"),
+                    COLLECTION, null, "item", COMMA));
             SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
             return this.addDeleteMappedStatement(mapperClass, getMethod(sqlMethod), sqlSource);
         }