mybatis 当需要批量插入并更新主键相同的数据时的处理方法

该方法 如果表中没有没有主键对应的数据就添加一条 如果有的话就更新该条数据

<insert id="insertBatch">
    REPLACE into representatives_and_principal_personnel
    (id,examine_and_approve_id, idcard_number, name, sex, duty, rankv, birth,
    standard_culture, workspace, state, phone, have_bad_record, amount_of_contribution)
    values
    <foreach collection="list" item="representativesAndPrincipalPersonnel" separator=",">
        (#{representativesAndPrincipalPersonnel.id},
        #{representativesAndPrincipalPersonnel.examine_and_approve_id},
        #{representativesAndPrincipalPersonnel.idcard_number},
        #{representativesAndPrincipalPersonnel.name},
        #{representativesAndPrincipalPersonnel.sex},
        #{representativesAndPrincipalPersonnel.duty},
        #{representativesAndPrincipalPersonnel.rankv},
        #{representativesAndPrincipalPersonnel.birth},
        #{representativesAndPrincipalPersonnel.standard_culture},
        #{representativesAndPrincipalPersonnel.workspace},
        #{representativesAndPrincipalPersonnel.state},
        #{representativesAndPrincipalPersonnel.phone},
        #{representativesAndPrincipalPersonnel.have_bad_record},
        #{representativesAndPrincipalPersonnel.amount_of_contribution})
    </foreach>
</insert>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值