ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java中的批量导入,批量更新数据

2022-07-19 11:03:02  阅读:259  来源: 互联网

标签:VARCHAR monitor 批量 sample item 导入 jdbcType java id


批量插入 数据,提高效率

 

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>

  

 

 

 

标签:VARCHAR,monitor,批量,sample,item,导入,jdbcType,java,id
来源: https://www.cnblogs.com/xingmeng63/p/16493271.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有