//批量添加V1
public void batchInsert(){
int limit = 4;
int size = list.size();
int listSize = size <= limit ? 0 : limit;
for (int begin = 0; begin < size; begin = begin + listSize) {
int end = (begin + listSize > size ? size : begin + listSize);
List<Integer> subTaskLists = listSize == 0 ? list : list.subList(begin, end);
System.out.println(subTaskLists);
if (listSize == 0) {
break;
}
}
}
//批量添加V2
public void batchInsert(){
int limit = 5;
int count = list.size();
int batchSelectCount = count % limit == 0 ? count / limit : count / limit + 1;
int start = 0;
int end = 0;
for (int i=1;i<=batchSelectCount;i++) {
if(i == batchSelectCount){
if (count%limit == 0){
end = end + limit;
}else {
end = end + count%limit;
}
}else {
end = end + limit;
}
List<Integer> subSceneBlackImageList = list.subList(start, end);
start = end;
System.out.println(subSceneBlackImageList);
}
}
MySQL批量添加
于 2022-01-21 16:47:18 首次发布