mybatis 3 批量插入返回主键 Parameter 'id' not found

时间:2022-12-28 15:06:40
@Insert("<script>INSERT INTO scp_activity_gift (activity_id,type,gift_id,status,limit_num,num)  "
+ "VALUES "
+" <foreach collection='items' item='item' separator=',' >"
+"(#{item.activityId},#{item.type},#{item.giftId},#{item.status},#{item.limitNum},#{item.num})"
+" </foreach>"
+ "</script>")
@Options(useGeneratedKeys = true, keyProperty = "id")
Integer batchActivityGift(@Param("items")List<ActivityGiftPO> items);

这个会抛异常   Parameter 'id' not found

把 useGeneratedKeys = true  改成 useGeneratedKeys = false

来自:https://www.cnblogs.com/smallstudent/p/5924213.html

https://blog.csdn.net/danchaofan0534/article/details/77095159

以上问题解决了id not  found   然而没有达到我想要的  列表返回主键id

@Insert("<script>INSERT INTO scp_active_offer_category_item (company_item_id,category_id,active_id) "
+ "VALUES "
+" <foreach collection='list' item='item' separator=',' >"
+"(#{item.companyItemId},#{item.categoryId},#{item.activeId})"
+" </foreach>"
+ "</script>")
@Options(useGeneratedKeys = true, keyProperty = "id",keyColumn="id")
Integer batchActiveItem(@Param("list")List<ActiveOfferCategoryItemPO> items);

collection对应的值请使用list

@Param("list")

来自:https://blog.csdn.net/kahhy/article/details/84248354