mysql 批量新增含有unique 字段约束的方案

1.在代码里将列表对该字段进行去重,可以考虑用Set

2.

 insert ignore into,遇到错误跳过,即重复的话会跳过,执行下一条
<insert id="insertDeptList">
        insert ignore into yx_admin_dept (dept_id,pid,name,dept_type,is_deleted,owner_user_name,
        parentdept,code) values
        <foreach collection="adminDeptList" item="item" index="index" separator=",">
            (#{item.deptId},#{item.pid},#{item.name},#{item.deptType},#{item.isDeleted},#{item.ownerUserName},
        #{item.parentdept},#{item.code})
        </foreach>
    </insert>

 

posted @   了悟  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示