单条插入
useGeneratedKeys设置为true,keyProperty为要回填的属性名
<insert id="insertBook" useGeneratedKeys="true" keyProperty="id">
insert into t_book (b_name,author) values (#{name},#{author});
</insert>
批量插入
int batchInsert(@Param("list") List<CarSourceFollow> carSourceFollowList);
注意:foreach标签中collection的名字必须为list,不然不会回填成功
<insert id="batchInsert" parameterType="list" useGeneratedKeys="true" keyProperty="id">
insert into car_source_follow (car_source_id, user_id, follow_type, follow_progress, content, img_link) values
<foreach collection="list" item="item" separator=",">
(#{item.carSourceId}, #{item.userId}, #{item.followType}, #{item.followProgress}, #{item.content}, #{item.imgLink})
</foreach>
</insert>
参考博客
[1]https://www.cnblogs.com/lenve/p/10760373.html