zoukankan      html  css  js  c++  java
  • mybatis 3 批量插入返回主键 Parameter 'id' not found

    @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

  • 相关阅读:
    CentOS下crond定时任务详细介绍
    js随机从数组中取出几个元素
    js复制内容加版权声明代码
    crond不执行原因分析
    2015年最全的移动WEB前端UI框架
    聊聊前端排序的那些事
    Linux下修改Mysql的用户(root)的密码
    SIPp常用脚本之三:UAC
    SIPp常用脚本之二:UAS
    SIPp常用脚本之一:register注册
  • 原文地址:https://www.cnblogs.com/lanliying/p/11007798.html
Copyright © 2011-2022 走看看