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>
下班记得打卡