mybatis批量导入或插入重复数据处理

设置mysql 索引

创建mysql索引

在mybatis.xml里面使用 ON DUPLICATE KEY UPDATE

  <insert id="insertZfCompanyList">
        insert into zf_company (
        com_id,
        zf_user_id,
        com_name,
        register_sta,
        com_people,
        com_capital,
        esta_time,
        roval_time,
        com_pro,
        com_city,
        com_area,
        com_phone,
        com_phone2,
        com_email,
        com_email2,
        com_code,
        com_id_code,
        com_register,
        com_organ,
        insured_no,
        com_type,
        com_trade,
        once_name,
        web_site,
        com_address,
        report_address,
        com_scope,
        com_stutas,
        create_by,
        create_time,
        update_by,
        update_time,
        expire_time,
        is_opening,
        remark,
        creation
        ) values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.comId},
            #{item.zfUserId},
            #{item.comName},
            #{item.registerSta},
            #{item.comPeople},
            #{item.comCapital},
            #{item.estaTime},
            #{item.rovalTime},
            #{item.comPro},
            #{item.comCity},
            #{item.comArea},
            #{item.comPhone},
            #{item.comPhone2},
            #{item.comEmail},
            #{item.comEmail2},
            #{item.comCode},
            #{item.comIdCode},
            #{item.comRegister},
            #{item.comOrgan},
            #{item.insuredNo},
            #{item.comType},
            #{item.comTrade},
            #{item.onceName},
            #{item.webSite},
            #{item.comAddress},
            #{item.reportAddress},
            #{item.comScope},
            #{item.comStutas},
            #{item.createBy},
            #{item.createTime},
            #{item.updateBy},
            #{item.updateTime},
            #{item.expireTime},
            #{item.isOpening},
            #{item.remark},
            #{item.creation}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
        register_sta = VALUES(register_sta),
        com_people = VALUES(com_people),
        com_capital = VALUES(com_capital),
        esta_time = VALUES(esta_time),
        roval_time = VALUES(roval_time),
        com_pro = VALUES(com_pro),
        com_city = VALUES(com_city),
        com_area = VALUES(com_area),
        com_phone = VALUES(com_phone),
        com_phone2 = VALUES(com_phone2),
        com_email = VALUES(com_email),
        com_email2 = VALUES(com_email2),
        com_code = VALUES(com_code),
        com_id_code = VALUES(com_id_code),
        com_register = VALUES(com_register),
        com_organ = VALUES(com_organ),
        insured_no = VALUES(insured_no) ,
        com_type = VALUES(com_type) ,
        com_trade = VALUES(com_trade) ,
        once_name = VALUES(once_name) ,
        web_site = VALUES(web_site) ,
        com_address = VALUES(com_address) ,
        report_address= VALUES(report_address) ,
        com_scope = VALUES(com_scope) ,
        com_stutas = VALUES(com_stutas) ,
        create_by = VALUES(create_by) ,
        create_time = VALUES(create_time) ,
        update_by = VALUES(update_by) ,
        update_time = VALUES(update_time) ,
        expire_time = VALUES(expire_time) ,
        is_opening = VALUES(is_opening) ,
        remark = VALUES(remark) ,
        creation= VALUES(creation)
    </insert>

在批量插入的时候 如果有重复的索引会自动更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值