【java】【mybatis】在使用mybatis進行批量插入,批量更新等批量操作時,切割In集合List進行分批批量操作的java中的切割代碼
阿新 • • 發佈:2018-09-13
lse span ati 批量更新 次數 sublist 調用 size ==
紅字部分代表mybatis的批量操作調用方法:
int num = 0; int maxLength = 200; int size = usableCodes.size(); if (size <= maxLength) { bean = createBean(bean,entity,usableCodes); num = receiptMapper.receipt(bean); } else {// 計算循環次數 int eachTime = (size / maxLength) + 1; for (int i = 0; i < eachTime; i++) { int fromIndex = 0; int toIndex = 0; fromIndex = (i * maxLength); toIndex = (fromIndex + maxLength);if (i + 1 == eachTime) { toIndex = usableCodes.size(); } List<String> subList = usableCodes.subList(fromIndex, toIndex); if (subList.size() > 0) { bean = createBean(bean,entity,subList); num+= receiptMapper.receipt(bean); } } }
【java】【mybatis】在使用mybatis進行批量插入,批量更新等批量操作時,切割In集合List進行分批批量操作的java中的切割代碼