From e54033f4e43b386a492af1cb25b5f539b34eb205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Mon, 30 Aug 2021 12:24:24 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20saveOrUpdateAll?= =?UTF-8?q?=20=E7=A9=BA=E5=88=97=E8=A1=A8=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/mybatisplus/core/ServicePlusImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java index 6f73c43a3..fab1e4833 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.common.core.mybatisplus.core; import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.TableInfo; @@ -134,6 +135,9 @@ public class ServicePlusImpl, T, V> extends ServiceI */ @Override public boolean saveOrUpdateAll(Collection entityList) { + if (CollUtil.isEmpty(entityList)) { + return false; + } TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); String keyProperty = tableInfo.getKeyProperty(); @@ -149,10 +153,10 @@ public class ServicePlusImpl, T, V> extends ServiceI updateList.add(entity); } } - if (updateList.size()>0 && updateBatchById(updateList)) { + if (CollUtil.isNotEmpty(updateList) && updateBatchById(updateList)) { row += updateList.size(); } - if (addList.size() > 0) { + if (CollUtil.isNotEmpty(addList)) { row += baseMapper.insertAll(addList); } return row == entityList.size();