mybatis 批量插入数据后得到自增主键(mysql)

Integer addAttachmentInfo(List<Attachment> list);
<insert id="addAttachmentInfo" parameterType="java.util.List" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO attachment (url,name,volume_id,upload_person_id,upload_time,file_size) values

        <foreach collection="list" item="item" index="index" separator=",">
                ( #{item.url}, #{item.name}, #{item.volumeId}, #{item.uploadPersonId}, #{item.uploadTime}, #{item.fileSize})
        </foreach>
    </insert>

执行后插入后,可以看到list中的实体有自增id了

猜你喜欢

转载自blog.csdn.net/weixin_38323645/article/details/119054051