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); }
--
沉着,冷静,bug总会解决,未来道路很光明。