import java.util.List;
import java.util.function.Consumer;
public class BatchSaveUtils {
private BatchSaveUtils() {
}
public static <T> void batchSave(List<T> l, int perCount, Consumer<List<T>> c) {
if (perCount <= 0) {
throw new IllegalArgumentException("perCount 必须大于0");
} else {
for(int startIndex = 0; startIndex < l.size(); startIndex += perCount) {
int endIndex = startIndex + perCount > l.size() ? l.size() : startIndex + perCount;
c.accept(l.subList(startIndex, endIndex));
}
}
}
}
Java分批执行list集合
最新推荐文章于 2024-07-17 04:44:13 发布