mybatis批量插入
dao层方法
public void batchInsertTTaskPara(List<TTaskPara> tTaskParaList) throws INASSQLException { long st = new Date().getTime(); getSqlSession().insert("com.ustcinfo.inas.bussinessCheck.dao.sqlmap.TTaskParaMapper.batchInsertTTaskPara2",tTaskParaList); long et = new Date().getTime(); logger.debug("插入共花费-------------------:"+(et-st)+"ms"); }
mapper.xml
<select id="batchInsertTTaskPara" parameterType="java.util.List"> insert into T_TASK_PARA(task_id ,rpt_seq, node_code,node_value,node_tran_value) <foreach collection="list" item="item" index="index" separator="union all" > select #{item.taskId}, #{item.rptSeq}, #{item.nodeCode}, #{item.nodeValue}, #{item.nodeTranValue} from dual </foreach> </select>
测试方法
public static void main(String[] args) throws Exception { List<TTaskPara> tTaskParaList = new ArrayList<TTaskPara>(); for(int i=0;i<150;i++){ TTaskPara taskPara = new TTaskPara(); taskPara = new TTaskPara(); taskPara.setTaskId(200003l); taskPara.setRptSeq(2l); taskPara.setNodeCode("AUTH" + i); taskPara.setNodeValue("SN"); taskPara.setNodeTranValue("SN"); tTaskParaList.add(taskPara); } TTaskParaDao tTaskParaDao =ApplicationContextProxy.getBean(TTaskParaDaoImpl.class); tTaskParaDao.batchInsertTTaskPara(tTaskParaList); }