Java:批量插入数据


	import com.google.common.collect.Lists;
	import org.springframework.util.CollectionUtils;


	private void add() {
		List<CeshiBean> ceshiList = new ArrayList<CeshiBean>();
        if(CollectionUtils.isEmpty(ceshiList )){
            log.info("无数据");
            return;
        }
        
		// 分批插入数据库:每次插入2000条
        List<List<CeshiBean>> dataList = Lists.partition(ceshiList,2000);
        dataList.forEach(x->{
            ceshiMapper.add(x);
            log.info("已插入{}条记录",x.size());
        });
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章