MyBatis批量新增和更新】的更多相关文章

之前有开发任务一个接口里面有大量的数据新增和更新操作,导致十分缓慢.使用了批量操作之后速度有明显提升,几乎百倍千倍的速度提升. 博主之前统计过,通过普通接口一次数据库插入大概需要200ms,对于大量新增或更新操作的情况,数据库批量操作是十分有必要的.废话不多说,直接上代码. 博主的resultMap如下: <resultMap id="BaseResultMap" type="com.luo.domain.Words" > <id column=&…
mysql中在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE时,向数据库中插入一条记录: 若插入数据的主键值/ UNIQUE KEY 已经在表中存在,则执行更新操作(UPDATE 后面的操作),否则插入一条新的记录 格式 INSERT tbl_name [(col_name,...)] VALUES (expr,...),(...),... ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... 在myba…
1.批量更新或者新增 1.单个新增或者更新 keyProperty新增完之后返回Id值…
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 , creat…
SpringBoot配置Mybatis前文有博文,数据库mysql: package com.example.demo.biz.dto; public class User { private int id; private String userName; private String passWord; private String gender; private String email; private String mobile; private String identity; pr…
1.插入 (1)第一种方式:利用<foreach>标签,将入参的list集合通过UNION ALL生成虚拟数据,从而实现批量插入(验证过) <insert id="insertBatchLaTContactRecord" parameterType="java.util.Map"> <selectKey resultType="java.lang.Long" keyProperty="dto.id"…
批量插入 <insert id="add" parameterType="java.util.List"> insert all <foreach item="item" index="index" collection="list" open="" separator="" close=""> into PARAMETET…
虽然是很基础的东西,不过难免会忘记,所以写个笔记巩固一下,顺便分享. 实体类: @Data public class EventOrder { ​ private Long id; ​ private String eventName; ​ private Integer eventType; ​ private String orderNo; ​ } 表字段: 批量添加 <sql id="BaseColumn"> `id`, event_name, event_type,…
前面介绍了无主键的表的批量插入,文章地址:http://blog.csdn.net/zhouxiaoyun0228/article/details/9980181 但是在开发中往往许多的表是需要主键的,因而现在介绍一下有主键的表的批量插入,该主键是数据类型的数字类型. 最开始我是这么想的:主键让他自动添加,因而我们可以在insert中添加一个自增序列号就可以了,如下 <selectKey resultType="long" keyProperty="ID" o…
org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for t…