参考来自:mybatis mysql 批量insert 返回主键

注意:必须要在mybatis3.3.1及其以上才能实现。

1.service

 List branchEntryList = (ArrayList<Entry>)entryMap.get("branchEntryList");
branchDao.insertBatch(branchEntryList);

2.dao

3.xml

注意这里是list,不管参数名叫什么,这里都是list。

4.效果

执行前,branchEntryList里的对象是没有id的值的。

执行完后,查看变量branchEntryList,可以看到主键已经回填了。

5.其他

在查资料的时候,说这种方式支持map和list。

于是使用Map:

(1)insertMap.insert("branchEntryList",branchEntryList);

(2)int insertBatch(Map<String,Object> insertMap);

(3)parameterType="java.util.Map"

(4)<foreach collection="branchEntryList" ...

但是主键并没有回填。将Map的类型改为<String,List<Entry>>,主键则成功回填。所以使用此项功能的时候,List<Entry>必须指明,不管是不是放在map里。

2017.9.15 mybatis批量插入后实现主键回填的更多相关文章

  1. mybatis批量插入并返回主键(序列)-oracle

    需求:批量插入数据,并返回每条数据的主键(序列),因为这里是采用序列生成唯一的主键的, 其实oracle批量 插入操作有几种,网上百度都是有相关资源的.但是笔者现在的需求是,不仅批量插入数据后,并返回 ...

  2. Mybatis之MySql批量insert后返回主键

    需求:使用批量插入后,需要insert之后的每一条记录的ID 注意:Mybatis3.3.1的版本以后支持批量插入后返回主键ID 示例: domin.java: public class User { ...

  3. myBatis获取批量插入数据的主键id

    在myBatis中获取刚刚插入的数据的主键id是比较容易的 , 一般来说下面的一句话就可以搞定了 , 网上也有很多相关资料去查. @Options(useGeneratedKeys = true, k ...

  4. Mybatis返回插入数据的主键的两种方式

    方式一: 需要在映射文件中添加如下片段: <insert id="insertProduct" parameterType="domain.model.Produc ...

  5. MyBatis中插入并返回主键

    开发过程中经常遇到需要插入一条数据,并且返回这条数据自增的主键,在MyBatis中只需要在mapper中添加keyProperty属性即可 在mapper中添加keyProperty属性 <in ...

  6. 2017.9.15 postgresql批量插入造成冲突后执行更新

    参考来自:https://stackoverflow.com/questions/40647600/postgresql-multi-value-upserts/46233907#46233907 1 ...

  7. mybatis获取插入的语句主键(自增主键)

    <insert id="insertUser" parameterType="User"> <selectKey keyProperty=&q ...

  8. Mybatis配置插入数据返回主键ID

    需要在insert方法中添加 <insert id="insertSelective" parameterType="com.midou.ott.model.MDA ...

  9. mybatis批量插入oracle

    <insert id="batchInsert" parameterType="java.util.List"> INSERT INTO TEST( ...

随机推荐

  1. 手把手搭建一个完整的javaweb项目

    手把手搭建一个完整的javaweb项目 本案例使用Servlet+jsp制作,用MyEclipse和Mysql数据库进行搭建,详细介绍了搭建过程及知识点. 下载地址:http://download.c ...

  2. NOIP2012提高组

    D1T1.Vigenère密码 模拟 #include<iostream> #include<cstdio> using namespace std; int main() { ...

  3. error LNK2001: 无法解析的外部符号 "public: virtual long __stdcall CBaseFilter(转)

    原文转自 https://www.cnblogs.com/xiongjiaji/archive/2010/12/31/2476565.html 今天用VS2005编译DirectShow程序,发现出来 ...

  4. VLC for iOS 2.3.0

    http://www.cocoachina.com/bbs/read.php?tid=231898 VLC for iOS 2.3.0       本帖属于CocoaChina会员发表,转帖请写明来源 ...

  5. 请求路径@PathVariable与请求参数@RequestParam的区别

    转自:http://www.iteye.com/problems/101566: http://localhost:8080/Springmvc/user/page.do?pageSize=3& ...

  6. 或许你不知道的10条SQL

    一.一些常见的SQL实践 (1)负向条件查询不能使用索引 select * from order where status!=0 and stauts!=1 not in/not exists都不是好 ...

  7. Centos7部署Open-Falcon监控

    参考博主:努力哥完成 一.Open-Falcon介绍 1.监控系统,可以从运营级别(基本配置即可),以及应用级别(二次开发,通过端口进行日志上报),对服务器.操作系统.中间件.应用进行全面的监控,及报 ...

  8. Guava源码学习(四)新集合类型

    基于版本:Guava 22.0 Wiki:New collection types 0. 简介 Guava提供了很多好用的集合工具,比如Multiset和BiMap,本文介绍了这些新集合类型的使用方式 ...

  9. HDU 3466 Proud Merchants【贪心 + 01背包】

    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...

  10. Codeforces Round #262 (Div. 2) A. Vasya and Socks【暴力/模拟/袜子在可以在合法情况下增加后用几天】

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...