java中的批量导入,批量更新数据
批量插入 数据,提高效率
Dao层
1 | int insertBatch(List<HealthImport> list); |
xml文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <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层
1 | int updateBatch(List<HealthImport> list); |
xml文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | <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> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!