记录一下,留着后用
java
//每次批量插入的数量 int limitSize = 500; //总共可以分几页 int count = (int) Math.ceil((double) list.size() / limitSize); for (int i = 0; i <= count - 1; i++) { if (i == count - 1) { orderMapper.batchInsert(list.subList(i * limitSize, list.size())); } else { orderMapper.batchInsert(list.subList(i * limitSize, i * limitSize + limitSize)); } }
mapper.xml
<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false"> insert into table ( ID, FEE_DATE, CREATETIME ) SELECT TABLE_SEQ.Nextval, a.* FROM ( <foreach collection="list" item="item" index="index" separator ="UNION ALL"> SELECT #{item.feeDate,jdbcType=VARCHAR}, #{item.createtime,jdbcType=VARCHAR} FROM dual </foreach> ) a </insert>
id是创建的自增序列