批量插入 数据,提高效率

Dao层

int insertBatch(List<HealthImport> list);

 

xml文件

<insert id="insertBatch" parameterType="java.util.List" >
insert into health_import
(answer_id, sample_num, `name`,
sex, age, select_goal,
pro_id, pro_name, select_result,
sample, patient_id, barcode,
reviewer, idcard, refer_range,
unit, create_time, `result`,
flag, message)
values
<foreach collection="list" index="index" item="monitor" separator=",">
(#{monitor.answerId,jdbcType=INTEGER}, #{monitor.sampleNum,jdbcType=VARCHAR}, #{monitor.name,jdbcType=VARCHAR},
#{monitor.sex,jdbcType=VARCHAR}, #{monitor.age,jdbcType=VARCHAR}, #{monitor.selectGoal,jdbcType=VARCHAR},
#{monitor.proId,jdbcType=VARCHAR}, #{monitor.proName,jdbcType=VARCHAR}, #{monitor.selectResult,jdbcType=VARCHAR},
#{monitor.sample,jdbcType=VARCHAR}, #{monitor.patientId,jdbcType=VARCHAR}, #{monitor.barcode,jdbcType=VARCHAR},
#{monitor.reviewer,jdbcType=VARCHAR}, #{monitor.idcard,jdbcType=VARCHAR}, #{monitor.referRange,jdbcType=VARCHAR},
#{monitor.unit,jdbcType=VARCHAR}, #{monitor.createTime,jdbcType=TIMESTAMP}, #{monitor.result,jdbcType=INTEGER},
#{monitor.flag,jdbcType=INTEGER}, #{monitor.message,jdbcType=VARCHAR})
</foreach>
</insert>

  

批量 更新数据 提高效率

Dao层

int updateBatch(List<HealthImport> list);

  

xml文件

<update id="updateBatch" parameterType="java.util.List" >
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update health_import
<set>
<if test="item.answerId != null">
answer_id = #{item.answerId,jdbcType=INTEGER},
</if>
<if test="item.sampleNum != null">
sample_num = #{item.sampleNum,jdbcType=VARCHAR},
</if>
<if test="item.name != null">
`name` = #{item.name,jdbcType=VARCHAR},
</if>
<if test="item.sex != null">
sex = #{item.sex,jdbcType=VARCHAR},
</if>
<if test="item.age != null">
age = #{item.age,jdbcType=VARCHAR},
</if>
<if test="item.selectGoal != null">
select_goal = #{item.selectGoal,jdbcType=VARCHAR},
</if>
<if test="item.proId != null">
pro_id = #{item.proId,jdbcType=VARCHAR},
</if>
<if test="item.proName != null">
pro_name = #{item.proName,jdbcType=VARCHAR},
</if>
<if test="item.selectResult != null">
select_result = #{item.selectResult,jdbcType=VARCHAR},
</if>
<if test="item.sample != null">
sample = #{item.sample,jdbcType=VARCHAR},
</if>
<if test="item.patientId != null">
patient_id = #{item.patientId,jdbcType=VARCHAR},
</if>
<if test="item.barcode != null">
barcode = #{item.barcode,jdbcType=VARCHAR},
</if>
<if test="item.reviewer != null">
reviewer = #{item.reviewer,jdbcType=VARCHAR},
</if>
<if test="item.idcard != null">
idCard = #{item.idcard,jdbcType=VARCHAR},
</if>
<if test="item.referRange != null">
refer_range = #{item.referRange,jdbcType=VARCHAR},
</if>
<if test="item.unit != null">
unit = #{item.unit,jdbcType=VARCHAR},
</if>
<if test="item.createTime != null">
create_time = #{item.createTime,jdbcType=TIMESTAMP},
</if>
<if test="item.result != null">
`result` = #{item.result,jdbcType=INTEGER},
</if>
<if test="item.flag != null">
flag = #{item.flag,jdbcType=INTEGER},
</if>
<if test="item.message != null">
message = #{item.message,jdbcType=INTEGER}
</if>
</set>
where pro_id = #{item.proId,jdbcType=VARCHAR} and sample_num = #{item.sampleNum,jdbcType=VARCHAR}
</foreach>
</update>

  

 

java中的批量导入,批量更新数据的更多相关文章

  1. java中,字符串类型的时间数据怎样转换成date类型。

    将字符串类型的时间转换成date类型可以使用SimpleDateFormat来转换,具体方法如下:1.定义一个字符串类型的时间:2.创建一个SimpleDateFormat对象并设置格式:3.最后使用 ...

  2. [diango]批量导入不重复数据

    去年研究导入数据的时候写了一个批量导入数据的脚本,但有个问题,如果导入这批数据在数据库中已经存在,那么我们导入的数据不就重复了么,本文就讨论如何解决这个问题? 程序如下: #coding:utf-8 ...

  3. hibernate批量删除和更新数据

    转载自:http://blog.csdn.net/yuhua3272004/article/details/2909538 Hibernate3.0 採用新的基于ANTLR的HQL/SQL查询翻译器, ...

  4. mybatis 注解的方式批量插入,更新数据

    一,当向数据表中插入一条数据时,一般先检查该数据是否已经存在,如果存在更新,不存在则新增  使用关键字  ON DUPLICATE KEY UPDATE zk_device_id为主键 model  ...

  5. sequelize 批量添加和更新数据 bulkCreate

    sequelize提供了批量插入数据的方法:Model.bulkCreate([…object]). 例如: let  updatePhone = [{userName: '李白‘},{userNam ...

  6. SQL server 批量插入和更新数据

    批量插入数据 insert into A表数据库名.[dbo].A(a,b,c) (select a,b,c from B表数据库名.[dbo].B) 批量更新数据 根据身份证第二位更新性别 upda ...

  7. java中使用poi导出excel表格数据并且可以手动修改导出路径

    在我们开发项目中,很多时候会提出这样的需求:将前端的某某数据以excel表格导出,今天就给大家写一个简单的模板. 这里我们选择使用poi导出excel: 第一步:导入需要的jar包到 lib 文件夹下

  8. java 中Excel的导入导出

    部分转发原作者https://www.cnblogs.com/qdhxhz/p/8137282.html雨点的名字  的内容 java代码中的导入导出 首先在d盘创建一个xlsx文件,然后再进行一系列 ...

  9. .Net中DataAdapter批量插入和更新数据总结

    前言 前段时间一直在忙着项目上线,在做项目的同时遇到了一些之前不曾碰到的问题,因为没有经验,只能从网上找一些相关的解决方案,但是网上提供的资料实在是太杂,有的根本不能用,耗时又耗力. 我希望把我这段时 ...

  10. java中通过jacob调用dts进行数据导入导出

    在一个项目中需要金蝶软件对接,但是业务服务器和财务服务器相隔很远(中间经过好几台服务器,有内网也有外网),从一个内网向另一个内网中传输时,需要外网辅助,因为不让原始数据受污染,使用了DTS数据同步到另 ...

随机推荐

  1. python获取上月、当月、下月的开始和结束日期

    获取上月开始结束日期 方法一 import datetime def get_date_of_last_month(form="%Y-%m-%d"): ""&q ...

  2. MySQL数据库SQL语法常规操作

    必备sql和表关系及授权 graph LR 执行1[必备sql和授权] 执行2[SQL强化和实践] 执行3[索引和函数以及存储过程] 执行4[Python操作mysql和应用] 执行5[常见SQL语句 ...

  3. GitLab-Runner安装及使用

    Git_Lab CI Setting 根据该教程本地下载并安装 gitlab-runner.exe 在GitLab远程仓库页面点击 setting-> CI/CD ->runner Exp ...

  4. [Notes-DS-2]线性结构

    分割线------------- 分割线----------------

  5. Python学习的第一次总结

    执行Python的方式:1.交互器(不易保存,闪现,不方便看)2.用win-cmd 来执行(用notepad++保存后执行) 开始 >> cmd >> cd c:\ #切c盘& ...

  6. uniapp(1)

    **在项目根目录中新建.gitignore忽略文件,并配置如下: 忽略 node_modules /node_modules /unpackage/dist** 添加页面 新建页面,而后选择scss模 ...

  7. Camstar获取回参

    public static bool SplitQty(string Username, string Password, string Container, int splitQty,int pla ...

  8. 专业视频图片水印清除工具丨HitPaw Watermark Remover 2.1.3

    软件下载 MAC/Windows HitPaw Watermark Remover 软件介绍 HitPaw Watermark Remover 是一款能够轻松去除图片视频水印的软件.对于有水印的图片视 ...

  9. 《Makefile中传递宏定义到源文件》

    Makefile中定义的变量无法直接传递到头文件中,因为头文件是在预编译阶段处理的,而Makefile中的变量是在编译阶段处理的. 如果需要在头文件中使用Makefile中定义的变量,可以在头文件中使 ...

  10. 多线程问题sleep与wait

    涉及到的三个方法:wait():一旦执行此方法,当前线程就进入阻塞状态,并释放同步监视器notify():一旦执行此方法,就会唤醒被wait的一个线程.如果有多个线程被wait,就唤醒优先级高:not ...