记录一下,留着后用

 

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是创建的自增序列

 posted on 2021-11-09 15:01  布鲁布鲁sky  阅读(158)  评论(0编辑  收藏  举报