Ver Fonte

恢复错误修改的deleteBatchIds方法.

nieqiurong há 1 ano atrás
pai
commit
486e3b84de

+ 16 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

@@ -168,6 +168,19 @@ public interface BaseMapper<T> extends Mapper<T> {
      * 删除(根据ID或实体 批量删除)
      *
      * @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
+     * @deprecated 3.5.7 {@link #deleteByIds(Collection)}
+     */
+    @Deprecated
+    default int deleteBatchIds(@Param(Constants.COLL) Collection<?> idList) {
+        return deleteByIds(idList);
+    }
+
+
+    /**
+     * 删除(根据ID或实体 批量删除)
+     *
+     * @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
+     * @since 3.5.7
      */
     default int deleteByIds(@Param(Constants.COLL) Collection<?> idList) {
         return deleteByIds(idList, true);
@@ -186,16 +199,17 @@ public interface BaseMapper<T> extends Mapper<T> {
         SqlSession sqlSession = mybatisMapperProxy.getSqlSession();
         Class<?> mapperInterface = mybatisMapperProxy.getMapperInterface();
         TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
-        List<Object> ids = new ArrayList<>(collections.size());
         if (useFill && tableInfo.isWithLogicDelete() && tableInfo.isWithUpdateFill()) {
+            List<Object> ids = new ArrayList<>(collections.size());
             for (Object obj : collections) {
+                // TODO 乐观锁待定(感觉都要删除了,可以不用考虑乐观锁的情况了)...
                 if (entityClass.isAssignableFrom(obj.getClass())) {
                     ids.add(tableInfo.getPropertyValue(obj, tableInfo.getKeyProperty()));
                 } else {
                     ids.add(obj);
                 }
             }
-            this.update(tableInfo.newInstance(), Wrappers.<T>update().in(tableInfo.getKeyColumn(), ids));
+            return this.update(tableInfo.newInstance(), Wrappers.<T>update().in(tableInfo.getKeyColumn(), ids));
         }
         Map<String, Object> params = new HashMap<>();
         params.put(Constants.COLL, collections);

+ 2 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/logicdel/LogicDelTest.java

@@ -74,7 +74,8 @@ public class LogicDelTest extends BaseDbTest<EntityMapper> {
             entityList.add(entity2);
             assertThat(mapper.deleteByIds(entityList)).isEqualTo(2);
             entityList.forEach(entity -> {
-                Assertions.assertEquals("聂秋秋", entity.getDeleteBy());
+                //TODO 3.5.7 修改为使用IN的方式删除而不是使用行记录删除.
+//                Assertions.assertEquals("聂秋秋", entity.getDeleteBy());
             });
         });
 

+ 1 - 1
spring-boot-starter/mybatis-plus-spring-boot3-starter/src/test/java/com/baomidou/mybatisplus/test/pom/GeneratePomTest.java

@@ -62,7 +62,7 @@ class GeneratePomTest {
             Assertions.assertFalse(bom.isOptional());
             Assertions.assertEquals(dependenciesMap.get("spring-cloud-commons").getVersion(), "4.1.2");
             Assertions.assertEquals(dependenciesMap.get("mybatis-spring").getVersion(), "3.0.3");
-            Assertions.assertEquals(dependenciesMap.get("spring-boot-dependencies").getVersion(), "3.2.4");
+            Assertions.assertEquals(dependenciesMap.get("spring-boot-dependencies").getVersion(), "3.2.6");
         }
     }