默认分批是1000
一般也就改成100-1000之间示业务而定
比较简洁的一种方式如下
原代码
public Boolean insertTasks(List<TaskInfoEntity> tasks, String agentId) { // todo 分批 List<AgentTaskRelationEntity> entities = tasks.stream() .map((Function<TaskInfoEntity, AgentTaskRelationEntity>) task -> AgentTaskRelationEntity.builder() .agentId(agentId) .taskId(task.getTaskId()) .enabled(task.getEnabled()) .build()) .collect(Collectors.toList()); return xxx.saveBatch(entities); }
修改后的代码
public Boolean insertTasks(List<TaskInfoEntity> tasks, String agentId) { List<List<TaskInfoEntity>> batches = Lists.partition(tasks, BATCH_SIZE); for (List<TaskInfoEntity> batch : batches) { List<AgentTaskRelationEntity> entities = batch.stream() .map((Function<TaskInfoEntity, AgentTaskRelationEntity>) task -> AgentTaskRelationEntity.builder() .agentId(agentId) .taskId(task.getTaskId()) .enabled(task.getEnabled()) .build()) .collect(Collectors.toList()); xxx.saveBatch(entities); } return true; }
标签:task,mybatisplus,批量,分批,List,entities,tasks,agentId From: https://www.cnblogs.com/immersed-in-the-deep-sea/p/18176745