码迷,mamicode.com
首页 > 编程语言 > 详细

java后台大数据量下的分批入库

时间:2020-05-15 17:58:00      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:计数器   count   student   entity   obj   empty   计数   入库   sem   

对接入库数据,有时候数据量比较大,需要分批入库,写了一个分批入库的小方法

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);
                }
            }

简单记录使用

java后台大数据量下的分批入库

标签:计数器   count   student   entity   obj   empty   计数   入库   sem   

原文地址:https://www.cnblogs.com/innocenter/p/12895953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!