This commit is contained in:
开源海哥 2023-07-20 11:05:09 +08:00
commit cb8ed1735c
4 changed files with 20 additions and 11 deletions

View File

@ -4,4 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="#(packageConfig.mapperPackage).#(table.buildMapperClassName())">
</mapper>
</mapper>

View File

@ -11,4 +11,4 @@ import #(packageConfig.entityPackage).#(table.buildEntityClassName());
*/
public interface #(table.buildServiceClassName()) extends #(serviceConfig.buildSuperClassName())<#(table.buildEntityClassName())> {
}
}

View File

@ -121,4 +121,4 @@ public class #(table.buildServiceImplClassName()) extends #(serviceImplConfig.bu
}
#end
}
}

View File

@ -26,7 +26,10 @@ import com.mybatisflex.core.util.CollectionUtil;
import com.mybatisflex.core.util.SqlUtil;
import java.io.Serializable;
import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
@ -83,8 +86,6 @@ public interface IService<T> {
return saveBatch(entities, DEFAULT_BATCH_SIZE);
}
// ===== 删除操作 =====
/**
* <p>批量保存实体类对象数据
*
@ -93,10 +94,16 @@ public interface IService<T> {
* @return {@code true} 保存成功{@code false} 保存失败
*/
default boolean saveBatch(Collection<T> entities, int batchSize) {
return SqlUtil.toBool(getMapper().insertBatch(CollectionUtil.toList(entities), batchSize));
List<T> entityList = CollectionUtil.toList(entities);
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
return SqlUtil.toBool(
Db.executeBatch(entities.size()
, batchSize
, usefulClass
, (mapper, integer) -> mapper.insert(entityList.get(integer)))
);
}
/**
* <p>批量保存实体类对象数据
*
@ -107,8 +114,6 @@ public interface IService<T> {
return saveBatchSelective(entities, DEFAULT_BATCH_SIZE);
}
// ===== 删除操作 =====
/**
* <p>批量保存实体类对象数据
*
@ -120,10 +125,14 @@ public interface IService<T> {
List<T> entityList = CollectionUtil.toList(entities);
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
return SqlUtil.toBool(
Db.executeBatch(entities.size(), batchSize, usefulClass, (mapper, integer) -> mapper.insertSelective(entityList.get(integer)))
Db.executeBatch(entities.size()
, batchSize
, usefulClass
, (mapper, integer) -> mapper.insertSelective(entityList.get(integer)))
);
}
// ===== 删除操作 =====
/**
* <p>根据查询条件删除数据