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 @ 2023-05-16 23:56  了悟  阅读(35)  评论(0编辑  收藏  举报