在公司ERP项目开发中,遇到批量数据插入或者更新,因为每次连接数据库比较耗时,所以决定改为批量操作,提升效率。库存盘点导入时,需要大量数据批量操作。

1:数据库连接代码中必须开启批量操作。加上这句,&allowMultiQueries=true,完整的如下:

jdbc:mysql://localhost:3306/jeesite2016?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

2:批量更新 ,注意update的separator是;,和批量插入的不一样下载 。

  1. <update id="batchUpdateQuantity" parameterType="java.util.List">
  2. <foreach collection="list" item="item" index="index"  open="" close="" separator=";">
  3. update erp_store
  4. <set>
  5. quantity=#{item.quantity},
  6. update_date=#{item.updateDate}
  7. </set>
  8. where id = #{item.id}
  9. </foreach>
  10. </update>

经测试,一共1662条数据,批量插入用时466ms,循环单独插入用时1898ms。可以批量操作效率高很多。

3、批量插入下载

  1. <insert id="batchInsert">
  2. INSERT INTO erp_store_detail(
  3. id,
  4. store_id,
  5. type,
  6. change_quantity,
  7. after_quantity,
  8. update_date,
  9. remarks,
  10. link_id
  11. ) VALUES
  12. <foreach collection="list" item="item" index="index" separator="," >
  13. (
  14. #{item.id},
  15. #{item.store.id},
  16. #{item.type},
  17. #{item.changeQuantity},
  18. #{item.afterQuantity},
  19. #{item.updateDate},
  20. #{item.remarks},
  21. #{item.linkId}
  22. )
  23. </foreach>
  24. </insert>

mybatis3批量更新 批量插入的更多相关文章

  1. 如何 ︰ 执行批量更新和插入使用.NET 提供程序在 C#.NET OpenXML

    https://support.microsoft.com/zh-cn/kb/315968 如何 ︰ 执行批量更新和插入使用.NET 提供程序在 C#.NET OpenXML Email Prin ...

  2. MongoDB学习笔记~大叔分享批量添加—批量更新—批量删除

    回到目录 说它是批量操作,就是说将集合对象一次提交到服务器,并对数据进行持久化,如果您的代码是一次一次的提交,那不算是批量操作!在之前的mongodb仓储中并没有对批量更新和批量删除进行实现,而今天在 ...

  3. Mybatis批量更新和插入

    <update id="updateOrInsert"> <foreach collection="list" index="ind ...

  4. mysql根据查询结果批量更新多条数据(插入或更新)

    mysql根据查询结果批量更新多条数据(插入或更新) 1.1 前言 mysql根据查询结果执行批量更新或插入时经常会遇到1093的错误问题.基本上批量插入或新增都会涉及到子查询,mysql是建议不要对 ...

  5. mybatis+mysql批量插入和批量更新

    一.批量插入 批量插入数据使用的sql语句是: insert into table (字段一,字段二,字段三) values(xx,xx,xx),(oo,oo,oo) mybatis中mapper.x ...

  6. mybatis+mysql批量插入和批量更新、存在及更新

    mybatis+mysql批量插入和批量更新 一.批量插入 批量插入数据使用的sql语句是: insert into table (字段一,字段二,字段三) values(xx,xx,xx),(oo, ...

  7. 【转】Entity Framework Extended Library (EF扩展类库,支持批量更新、删除、合并多个查询等)

    E文好的可以直接看https://github.com/loresoft/EntityFramework.Extended 也可以在nuget上直接安装这个包,它的说明有点过时了,最新版本已经改用对I ...

  8. mybatis传入List实现批量更新

    如果要在一个update里面执行多条更新语句,只需要在jdbc:url后面跟上allowMultiQueries=true的参数,比如: jdbc:mysql://127.0.0.1:3306/tes ...

  9. mybatis批量更新update-设置多个字段值 报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

    mybatis批量更新update-设置多个字段值 2016年08月01日 12:49:26 姚一号 阅读数:29539 标签: mysql mybatis批量更新批量更新allowMultiQuer ...

随机推荐

  1. cordova 学习笔记

    0.sdk安装 http://spring.io/guides/gs/android/ 1.安装(node.js 需要安装https://nodejs.org/) on OS X and Linux: ...

  2. shell来start、stop、restart应用程序模板

    这里使用shell中的case语法: case分支语句格式如下: case $变量名 in 模式1) 命令列表 ;; 模式2) 命令列表 ;; *) ;; esac case行尾必须为单词“in”,每 ...

  3. windows7 中开启无线热点

    我用的是移动的 CMCC-EDU 上网,但是这个只能在一个设备上登陆,那么问题就来了,当我电脑需要用网,手机也想要用网(不用 2/3/4G)该怎么办? 电脑操作系统:windows7 接下来是开启 w ...

  4. MVC5入门

    http://www.cnblogs.com/youring2/p/mvc-5-examining-the-edit-methods-and-edit-view.html

  5. sp_executesql 两种写法

    写法1: AlTER PROCEDURE TryAgain @ReturnValue int output AS declare @aa nvarchar(), @ForumID int, @coun ...

  6. 从零开始Grunt

    [20141025]从0开始Grunt *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom ...

  7. 配置visual studio code进行asp.net core rc2的开发

    1.安装.net core sdk https://github.com/dotnet/cli#installers-and-binaries,根据你的系统选择下载. 2.下载vscode的C#扩展插 ...

  8. [Python] Search navigation in Pycharm

    From: http://blog.csdn.net/u013088062/article/details/50323393 From: http://blog.csdn.net/u013088062 ...

  9. jQuery带遮罩层弹窗实现(附源码)

    1.CSS样式 <style type="text/css"> body { font:11px/1.6em Microsoft Yahei; background:# ...

  10. debian之samba服务器搭建

    安装过程非常简单: apt-get install samba sudo vim /etc/sama/smb.conf [pengdl] comment = pengdl's samba path = ...