首页 > 其他分享 >mybatis实现批量插入更新 -- ON DUPLICATE KEY UPDATE

mybatis实现批量插入更新 -- ON DUPLICATE KEY UPDATE

时间:2023-01-31 21:22:57浏览次数:41  
标签:name -- UPDATE item DUPLICATE VALUES statistical indicators id

必须保证有唯一索引,可以是主键索引或者组合索引

<insert id="insertOrUpdate" parameterType="java.util.List">
        INSERT INTO indicators_template_detail_rep(
        id,indicators_name,indicators_id,dimension_name,dimension_id,
        index1, index2, index3, index4, index5, index6, index7,unit, statistical_cycle_name,
        statistical_type, stat_caliber, cal_logic,unit_id, statistical_cycle_id, statistical_type_id,
        cal_Logic_Id,response_dept_id,source_dept_name,response_dept_name, indicators_full_name,template_id
        ) VALUES
        <foreach collection="list" item="item"  separator=",">
            (
            #{item.id},#{item.indicatorsName},#{item.indicatorsId},#{item.dimensionName},#{item.dimensionId} ,
            #{item.index1} ,#{item.index2},#{item.index3},#{item.index4},#{item.index5},#{item.index6},#{item.index7},#{item.unit},#{item.statisticalCycleName},
            #{item.statisticalType},#{item.statCaliber},#{item.calLogic},#{item.unitId},#{item.statisticalCycleId},#{item.statisticalTypeId},
            #{item.calLogicId},#{item.responseDeptId},#{item.sourceDeptName},#{item.responseDeptName},#{item.indicatorsFullName},#{item.templateId}
            )
        </foreach>
         ON DUPLICATE KEY UPDATE
        is_deleted=0,
        indicators_name=VALUES(indicators_name),
        indicators_id=VALUES(indicators_id),
        dimension_name=VALUES(dimension_name),
        dimension_id=VALUES(dimension_id),
        index1=VALUES(index1),
        index2=VALUES(index2),
        index3=VALUES(index3),
        index4=VALUES(index4),
        index5=VALUES(index5),
        index6=VALUES(index6),
        index7=VALUES(index7),
        unit=VALUES(unit),
        statistical_cycle_name=VALUES(statistical_cycle_name),
        statistical_type=VALUES(statistical_type),
        stat_caliber=VALUES(stat_caliber),
        cal_logic=VALUES(cal_logic),
        unit_id=VALUES(unit_id),
        statistical_cycle_id=VALUES(statistical_cycle_id),
        statistical_type_id=VALUES(statistical_type_id),
        cal_Logic_Id=VALUES(cal_Logic_Id),
        response_dept_id=VALUES(response_dept_id),
        source_dept_name=VALUES(source_dept_name),
        response_dept_name=VALUES(response_dept_name),
        indicators_full_name=VALUES(indicators_full_name)
    </insert>
  

 

标签:name,--,UPDATE,item,DUPLICATE,VALUES,statistical,indicators,id
From: https://www.cnblogs.com/lansetuerqi/p/17080803.html

相关文章

  • restful规范、序列化与反序列化与drf下载及使用
    1.restful规范1.数据的安全保障:url链接一般都采用https协议进行传输---》为了保证数据安全使用https协议传输-https是什么:http+ssl/tsl2.接口中带aoi关键字比如:-https:......
  • 心理学-森田疗法
    2.【安大雄】https://www.bilibili.com/video/BV1Wo4y1d7QH/?spm_id_from=333.337.search-card.all.click&vd_source=08f2fe3f5caa2d2714e8d9d3d972cbf1......
  • 多线程--消费者与生产者实例
    多线程实例1.消费者与生产者实例(管程法)产品、消费者、生产者、缓冲区产品,保证有一个唯一标识即可消费者继承Thread,注册缓冲区,从缓冲区消费生产者继承Thread,注册缓冲......
  • 「☆□□」「能刺穿切開貶低制裁任何人的極惡而全能的神明大人」站在垃圾桶上等候真命天子。花一样抛洒的白色粉末,羽毛般洁白地融化在脑中。啊啊,错乱的闪白,遮盖视野的......
  • gitHub 提交代码
    1.首先在gitHub创建账号,然后创建一个仓库 2.push代码,提交代码时,URL填gitHub上的HTTPS的url    点击ok,会出现让登陆gitHub,可以填token登陆,登陆从gitHub上的se......
  • 2023第一个月总结
    对现有工作的不满意,发现身边人逐渐被生活改变,成为生活的累赘。工作的螺丝钉,机械且重复的活着,毫无新意。那我呢?对较好收入的屈服?不,我不想被生活摒弃,成为一颗螺丝钉。但我......
  • mac下载App报错
    mac下载App报错:该文件打不开,或者文件被破坏。一、解决方法:在“终端”输入:sudoxattr-dcom.apple.quarantine+(XXX.app)(XXX.app)是你在xxx.app在电脑的路......
  • E 清楚姐姐打怪升级【2023牛客寒假算法基础集训营4】
    E 清楚姐姐打怪升级原题链接代码点击查看代码#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#incl......
  • Docker部署Nacos自动停止运行
    1、现象使用docker部署的Nacos在运行一段时间后,就自动停止运行了。查看docker运行容器,nacos停止了2、解决因为是学生购买的轻量级服务器,所以配置很低,出现这种问题我默......
  • BZOJ 1852 [MexicoOI06] 最长不下降序列
    https://darkbzoj.cc/problem/1852首先解决初始排序的问题:先把\(i,j\)对应的两组数\((a_i,b_i),(a_j,b_j)\)分为“必要”,“非必要”两类。“必要”,指\(i\)必须......