java后台大數據量下的分批入庫


對接入庫數據,有時候數據量比較大,需要分批入庫,寫了一個分批入庫的小方法

if (!CollectionUtils.isEmpty(student)) {
                // 計數器
                int count = 1;
                int total = student.size();
                List<StudentEntity> stuList = new ArrayList();
                for (int f = 0; f < total; f++, count++) {
                    StudentEntity entity = student.get(f);
                    entity.setId(IdUtil.objectId());
                    stuList .add(entity);
                    //200條入庫一次
                    if (count % 200 == 0) {
                        studentService.insertBatchCustom(stuList);
                        stuList .clear();
                        count = 1;
                    }
                }
                if (!stuList .isEmpty()) {
                    studentService.insertBatchCustom(stuList);
                }
            }

簡單記錄使用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM