批量插入,批量修改的sql
sql 1 批量插入
<insert id="batchInsert" useGeneratedKeys="true" parameterType="java.util.List" >
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into user_contacts_info (id,user_id,old_id,cont_type,
cont_ship, cont_status, cont_source,
cont_user_name, cont_id_card, cont_mobile1,
cont_mobile2, cont_mobile3, cont_tell,
cont_addr, cont_addr_hk, cont_addr_com,
cont_tell_com, e_mail, remark, create_time,
cont_name_com,update_time)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.id,jdbcType=INTEGER},#{item.userId,jdbcType=INTEGER},#{item.oldId,jdbcType=INTEGER}, #{item.contType,jdbcType=VARCHAR},
#{item.contShip,jdbcType=VARCHAR}, #{item.contStatus,jdbcType=VARCHAR}, #{item.contSource,jdbcType=VARCHAR},
#{item.contUserName,jdbcType=VARCHAR}, #{item.contIdCard,jdbcType=VARCHAR}, #{item.contMobile1,jdbcType=VARCHAR},
#{item.contMobile2,jdbcType=VARCHAR}, #{item.contMobile3,jdbcType=VARCHAR}, #{item.contTell,jdbcType=VARCHAR},
#{item.contAddr,jdbcType=VARCHAR}, #{item.contAddrHk,jdbcType=VARCHAR}, #{item.contAddrCom,jdbcType=VARCHAR},
#{item.contTellCom,jdbcType=VARCHAR},#{item.eMail,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR},
#{item.createTime,jdbcType=TIMESTAMP}, #{item.contNameCom,jdbcType=VARCHAR},
#{item.updateTime,jdbcType=TIMESTAMP})
</foreach>
</insert> sql 2 批量插入,表设置为主键自增长
<insert id="insertByBatch" parameterType="java.util.List">
insert into monitor_log
(monitor_id, monitor_date, monitor_stats,
monitor_info,
monitor_product_id, monitor_repair_date,
monitor_repair_userid)
values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.monitorId,jdbcType=INTEGER},
#{item.monitorDate,jdbcType=TIMESTAMP},
#{item.monitorStats,jdbcType=TINYINT},
#{item.monitorInfo,jdbcType=VARCHAR},
#{item.monitorProductId,jdbcType=INTEGER},
#{item.monitorRepairDate,jdbcType=TIMESTAMP},
#{item.monitorRepairUserid,jdbcType=INTEGER})
</foreach>
</insert> sql 3 批量修改
<update id="updateBatch" parameterType="java.util.List">
update monitor_log
<trim prefix="set" suffixOverrides=",">
<trim prefix="monitor_date =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorDate !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorDate,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="monitor_stats =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorStats !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorStats,jdbcType=TINYINT}
</if>
</foreach>
</trim>
<trim prefix="monitor_info =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorInfo !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorInfo,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="monitor_product_id =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorProductId !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorProductId,jdbcType=INTEGER}
</if>
</foreach>
</trim>
where monitor_id in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.monitorId,jdbcType=BIGINT}
</foreach>
</update>
批量插入,批量修改的sql的更多相关文章
- 解决Oracle+Mybatis批量插入报错:SQL 命令未正确结束
Mybatis批量插入需要foreach元素.foreach元素有以下主要属性: (1)item:集合中每一个元素进行迭代时的别名. (2)index:指定一个名字,用于表示在迭代过程中,每次迭代到的 ...
- springMVC 接收数组参数,mybatis 接收数组参数,mybatis批量插入/批量删除案例
案例是给一个用户赋予多个权限,多个权限用其对应的主键 id 为参数,组成了 一个id数组,传给springMVC,然后springMVC传给mybatis,然后mybatis批量插入.其实类似的场景还 ...
- Dapper, 批量插入,批量更新, 以及in, like
1. 批量插入 public async Task CreateBusinessItemAsync(IEnumerable<BusinessItemsEntity> businessIte ...
- 【mybatis】mybatis中批量插入 批量更新 batch 进行insert 和 update,或者切割LIst进行批量操作
================================================================== 分别展示 mybatis 批量新增 和 批量更新 的操作: ...
- Java:批量插入、修改数据到数据库中的用法
在java中使用JDBC实现批处理的对象一般是使用PrepareStatement对象. 如何使用: Class.forName("Oracle.jdbc.driver.OracleDriv ...
- SSM批量插入和修改实现实例
1.Service,自己对代码逻辑进行相应处理 /* 新增订单产品信息 */ List<DmsOrderProduct> insertOrderProductList = Lists.ne ...
- mongodb 批量改变某一列类型 比如 String改为double,insert into select 批量插入 批量修改
//type:2代表String 1.String变Double db.集合.find({"列":{$type:2}}).forEach(function(x){ x.列=pars ...
- SQLite批量插入,修改数据库 zt
SQLiteConnection sqConnection = dataProvider.GetDbConnection(); sqConnection.Open(); SQLiteCommand s ...
- SQL Server 批量插入数据方案 SqlBulkCopy 的简单封装,让批量插入更方便
一.Sql Server插入方案介绍 关于 SqlServer 批量插入的方式,有三种比较常用的插入方式,Insert.BatchInsert.SqlBulkCopy,下面我们对比以下三种方案的速度 ...
- sql server中的大数据的批量操作(批量插入,批量删除)
首先我们建立一个测试用员工表 ---创建一个测试的员工表--- create table Employee( EmployeeNo int primary key, --员工编号 EmployeeNa ...
随机推荐
- sqlserver数据库的备份与还原——完整备份与还原
sqlserver提供四种数据库备份方式 完整备份:备份整个数据库的所有内容包括书屋和日志 差异备份:只备份上次完整备份后更高的数据部分 事务日志备份:只备份事务日志里的内容 文件或文件组备份:只备份 ...
- jquery滚动事件
滚动到一定高度: $(window).scroll(function(){ var scrollTop = $(document).scrollTop(); && scrollTop ...
- c#devexpress GridContorl添加进度条
demo 的实现图 下边是步骤和代码 1定义 时钟事件,定时的增加进度条的增量. 2: 添加进度条 3;定义字段属性 using System; using System.Collections.G ...
- txt写入时报错出现:正由另一进程使用,原来是多此一举的操作
//if (!File.Exists(newfilepath + "\\" + name + num + ".txt")) //{ // File.Create ...
- 5I - 汉诺塔IV
还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到小盘的上面.xhd在想如果我们允许最大的盘子放到最上面会怎么样 ...
- BZOJ 3131 [SDOI2013]淘金 - 数位DP
传送门 Solution 这道数位$DP$看的我很懵逼啊... 首先我们肯定要先预处理出 $12$位乘起来的所有的可能情况, 记录入数组 $b$, 发现个数并不多, 仅$1e4$不到. 然后我们考虑算 ...
- How to use external classes and PHP files in Laravel Controller?
By: Povilas Korop Laravel is an MVC framework with its own folder structure, but sometimes we want t ...
- macOS X Mount NFS Share / Set an NFS Client
last updated November 3, 2018 in CategoriesLinux, Mac OS X, UNIX How do I access my enterprise NAS s ...
- serial -1
#include <reg52.h>#include <stdio.h>#define uchar unsigned charsbit LED = P2^2;uchar rec ...
- 找不到类SimpleJdbcTemplate ParameterizedRowMapper cannot be resolved
找不到类SimpleJdbcTemplate 背景 想编译个web应用,原来spring-jdbc.jar用的是Spring 3.1,今天改成用Spring 4.3,报了这个错误. 现象 编译不通过, ...