mapper.xml

<!-- 批量新增 -->
<insert id="saveBatch" parameterType="java.util.List">
insert into t_gceb_login_log(
id ,
user_id ,
user_name ,
mip ,
jsession_id_4a ,
create_by ,
create_by_name ,
update_by ,
update_by_name ,
create_time ,
update_time ,
data_version ,
attribute1 ,
attribute2 ,
attribute3 ,
attribute4 ,
attribute5 ,
attribute6
)
values
<foreach collection="list" item="item" index="index" separator="," >
(
#{item.id},
#{item.userId},
#{item.userName},
#{item.mip},
#{item.jsessionId4a},
#{item.createBy},
#{item.createByName},
#{item.updateBy},
#{item.updateByName},
#{item.createTime},
#{item.updateTime},
#{item.dataVersion},
#{item.attribute1},
#{item.attribute2},
#{item.attribute3},
#{item.attribute4},
#{item.attribute5},
#{item.attribute6}
)
</foreach>
</insert> <!-- 批量修改 -->
<update id="updateBatch" parameterType="java.util.List">
update t_gceb_login_log
<trim prefix="set" suffixOverrides=",">
<trim prefix="userId =case" suffix="end,">
<foreach collection="list" item="item">
<if test="item.userId!=null">
when id=#{item.id} then #{item.userId}
</if>
</foreach>
</trim>
<trim prefix="attribute1 =case" suffix="end,">
<foreach collection="list" item="item">
<if test="item.attribute1!=null">
when id=#{item.id} then #{item.attribute1}
</if>
</foreach>
</trim>
</trim>
<where>
<foreach collection="list" separator="or" item="item">
id=#{item.id}
</foreach>
</where>
</update> <delete id="logBatchRemove" parameterType = "java.util.List">
delete from t_gceb_login_log
<where>
id in
<foreach collection="list" item="item" open="(" separator="," close=")" >
#{item}
</foreach>
</where>
</delete> 

注意点:批量操作也是有性能问题的,一个批次建议200条

List<List<LoginLog>> batchList = ListUtils.partition(loginLogList, 200);
for (List<LoginLog> array: batchList) {
int sum = this.sqlSessionTemplate.update("loginLog.updateBatch", array);
LOGGER.debug("批量更新记录数:{}", sum);
}

  

mybatis 批量新增-批量修改-批量删除操作的更多相关文章

  1. 17、手把手教你Extjs5(十七)模块的新增、修改、删除操作

    上节在Grid展示时做了一个金额单位可以手工选择的功能,如果你要加入其他功能,也只要按照这个模式来操作就行了,比如说你想改变金额字段的颜色.小数位数.零值是否显示.货币符号.单位显示在标题栏或者跟在金 ...

  2. mybatis,批量新增、修改,删除

    转载自:http://blog.csdn.net/sanyuesan0000/article/details/19998727 最近需要用到Mybatis批量新增oracle数据库,刚开始在网上找到的 ...

  3. MyBatis通过注解方式批量添加、修改、删除

    唯能极于情,故能极于剑 注: 本文转载于:CodeCow · 程序牛 的个人博客:http://www.codecow.cn/ 一.数据库实体DO public class User implemen ...

  4. 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作

    最近我做的一些项目,经常需要用到对应用程序的配置文件操作,如app.config和web.config的配置文件,特别是对配置文件中的[appSettings]和[connectionStrings] ...

  5. js操作select控件大全(包含新增、修改、删除、选中、清空、判断存在等)

    原文:js操作select控件大全(包含新增.修改.删除.选中.清空.判断存在等) js操作select控件大全(包含新增.修改.删除.选中.清空.判断存在等) js 代码// 1.判断select选 ...

  6. python操作三大主流数据库(14)python操作redis之新闻项目实战②新闻数据的展示及修改、删除操作

    python操作三大主流数据库(14)python操作redis之新闻项目实战②新闻数据的展示及修改.删除操作 项目目录: ├── flask_redis_news.py ├── forms.py ├ ...

  7. LitePal的修改和删除操作

    转载出处:http://blog.csdn.net/guolin_blog/article/details/40083685 传统的修改和删除数据方式   上篇文章中我们已经得知,SQLiteData ...

  8. c#封装DBHelper类 c# 图片加水印 (摘)C#生成随机数的三种方法 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象 c# 制作正方形图片 JavaScript 事件循环及异步原理(完全指北)

    c#封装DBHelper类   public enum EffentNextType { /// <summary> /// 对其他语句无任何影响 /// </summary> ...

  9. Entity Framework 6 Recipes 2nd Edition(10-8)译 - >映射插入、修改、删除操作到存储过程

    10-8. 映射插入.修改.删除操作到存储过程 问题 想要映射插入.修改.删除操作到存储过程 解决方案 假设已有运动员实体模型,如Figure 10-8所示. 对应的数据库表如Figure 10-9所 ...

  10. [PHP] - Laravel - 列表、新增、修改、删除例子

    前言 Laravel默认是自带了CURD的功能,使用路由的Route::resource可以做到. 但真正的项目中,这往往不是我们所需要的.因为一个项目会有比较复杂的计算.验证等功能. 下面是对项目中 ...

随机推荐

  1. 自己封装的mysql应用类示例

    from pymysql import *class my_mysql_mud(object): def __init__(self,host,port,db,user,passwd,charset= ...

  2. 存储单位 KB MB bit

  3. ExpressionHelp2

    public static class ExpressionHelp { private static Expression<T> Combine<T>(this Expres ...

  4. 用virtualenv建立Python独立开发环境

    1.用pip安装virtualenv sudo apt-get install python-virtualenv 2.1 创建python2的虚拟环境,进入要创建虚拟环境的目录下,我是放在/home ...

  5. web容器获取SSL指纹实现和ByPass

    @font-face { font-family: octicons-link; src: url("data:font/woff;charset=utf-8;base64,d09GRgAB ...

  6. CVPR2019论文看点:自学习Anchor原理

    CVPR2019论文看点:自学习Anchor原理 原论文链接:https://arxiv.org/pdf/1901.03278.pdf CVPR2019的一篇对anchor进行优化的论文,主要将原来需 ...

  7. TensorFlow分布式在Amazon AWS上运行

    TensorFlow分布式在Amazon AWS上运行 Amazon AWS 提供采用 NVIDIA K8 GPU 的 P2.x 机器.为了能够使用,第一步还需要创建一个 Amazon AWS 账户, ...

  8. MindSpore技术理解(上)

    MindSpore技术理解(上) 引言 深度学习研究和应用在近几十年得到了爆炸式的发展,掀起了人工智能的第三次浪潮,并且在图像识别.语音识别与合成.无人驾驶.机器视觉等方面取得了巨大的成功.这也对算法 ...

  9. GStreamer 1.0 series序列示例

    GStreamer 1.0 series序列示例 OpenEmbedded layer for GStreamer 1.0 这layer层为GStreamer 1.0框架提供了非官方的支持,用于Ope ...

  10. 孟老板 BaseAdapter封装 (三) 空数据占位图

    BaseAdapter封装(一) 简单封装 BaseAdapter封装(二) Header,footer BaseAdapter封装(三) 空数据占位图 BaseAdapter封装(四) PageHe ...