update 优化 saveOrUpdateAll 空列表校验
This commit is contained in:
parent
bfeca2cd7c
commit
e54033f4e4
@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.common.core.mybatisplus.core;
|
package com.ruoyi.common.core.mybatisplus.core;
|
||||||
|
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
@ -134,6 +135,9 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T, V> extends ServiceI
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean saveOrUpdateAll(Collection<T> entityList) {
|
public boolean saveOrUpdateAll(Collection<T> entityList) {
|
||||||
|
if (CollUtil.isEmpty(entityList)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
|
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
|
||||||
Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
|
Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
|
||||||
String keyProperty = tableInfo.getKeyProperty();
|
String keyProperty = tableInfo.getKeyProperty();
|
||||||
@ -149,10 +153,10 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T, V> extends ServiceI
|
|||||||
updateList.add(entity);
|
updateList.add(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updateList.size()>0 && updateBatchById(updateList)) {
|
if (CollUtil.isNotEmpty(updateList) && updateBatchById(updateList)) {
|
||||||
row += updateList.size();
|
row += updateList.size();
|
||||||
}
|
}
|
||||||
if (addList.size() > 0) {
|
if (CollUtil.isNotEmpty(addList)) {
|
||||||
row += baseMapper.insertAll(addList);
|
row += baseMapper.insertAll(addList);
|
||||||
}
|
}
|
||||||
return row == entityList.size();
|
return row == entityList.size();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user