List subList用法随笔记录

  List  subList用法随笔记录

 

 

   


int onceIndex=50;//一页记录数
int subCount = transactionInfos.size();//获取总记录数
int subPageTotal = (subCount / onceIndex) + ((subCount % onceIndex > 0) ? 1 : 0);//算出能分多少页
List< List<TransactionInfo>> addlist=new ArrayList<>();
// 根据页码取数据
for (int i = 0, len = subPageTotal - 1; i <= len; i++) {
    // 分页计算
    int fromIndex = i * onceIndex;
    int toIndex = ((i == len) ? subCount : ((i + 1) * onceIndex));
    List<TransactionInfo>   subList = transactionInfos.subList(fromIndex, toIndex);
    addlist.add(subList);
}
for (  List<TransactionInfo>   s : addlist) {
    this.transactionInfoMapper.insertTrans(s);
}

 

posted @ 2020-05-28 16:10  风中有朵云做的鱼  阅读(333)  评论(0编辑  收藏  举报