如何设计List的分段
不知道小伙伴有没有遇到这种情况,在一次插入大量数据到数据库时,由于超时的限制,有时候我们需要分批次去插入。反正我是遇到过这种情况的,要解决这样问题也很简单,那就是对数据进行分段,也就是对List进行分段。于是,我写了这样的方法。
public List<T> partionInsert(List<T> records, int limit) {
int fromIndex = 0;
List<List<T>> partionList = new ArrayList<>();
while(fromIndex < records.size()) {
int toIndex = Math.min(fromIndex + limit