mysql insert foreach 大数据量 重复

Posted wanghuanhuanlifeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql insert foreach 大数据量 重复相关的知识,希望对你有一定的参考价值。

 mysql insert foreach 大数据量时会产生重复的数据,数据会翻倍插入,解决方案:分批插入

List<AccessVO> batchInsertList =new ArrayList<>();
// 遍历原始数据,当临时容器 batchInsertList 长度为 1000 时,就插入一次,
// 然后清空 batchInsertList
for (AccessVO  tempMap: list) 
    batchInsertList.add(tempMap);
    if (batchInsertList.size() == 1000)
        //  System.out.println("==========="+length+"条数据插入=============="+batchInsertList.size());
        szxcVAccessMapper.insertSzxcVAccessBatch(batchInsertList);
        batchInsertList.clear();
    

// System.out.println("===========将剩余的数据也插入到表中=============="+batchInsertList.size());
// 将剩余的数据也插入到表中
szxcVAccessMapper.insertSzxcVAccessBatch(batchInsertList);

以上是关于mysql insert foreach 大数据量 重复的主要内容,如果未能解决你的问题,请参考以下文章