update 优化 saveOrUpdateAll 空列表校验

This commit is contained in:
疯狂的狮子li 2021-08-30 12:24:24 +08:00
parent bfeca2cd7c
commit e54033f4e4

View File

@ -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<M extends BaseMapperPlus<T>, T, V> extends ServiceI
*/
@Override
public boolean saveOrUpdateAll(Collection<T> 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<M extends BaseMapperPlus<T>, 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();