MyBatis批量插入并返回自动生成的ID


<insert id="batchInsertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List">
        insert into xxx_invoice
        (invoice_no, pin) values
        <foreach collection="list" item="item" index="index" separator=",">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.invoiceNo,jdbcType=VARCHAR}, #{item.pin,jdbcType=VARCHAR}
            </trim>
        </foreach>
</insert>

注意

  1. MyBatis版本3.3.1或者以上
  2. 传入的参数名称必须是"list"

你可能感兴趣的:(Java笔记)