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());
        });
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章