Mysql:

主键自增长。

加上:keyProperty="id"就可以获得了。

<insert id="insert" parameterType="entity" keyProperty="id" useGeneratedKeys="true">
insert into <include refid="t_user"/>
(name, code, version)
values (#{name}, #{code}, #{version})
</insert>

=========================================以下的方式也可以========================

*_mapper.xml:

<insert id="insert" parameterType="entity" useGeneratedKeys="true">
insert into <include refid="t_user"/>
(name, code, version)
values (#{name}, #{code}, #{version})
<selectKey resultType="long" keyProperty="id">
SELECT IF(row_count() > 0, last_insert_id(), 0) AS id FROM dual
</selectKey>
</insert>

就实现了插入之后获得主键的功能。

mybatis3 :insert返回插入的主键(selectKey)的更多相关文章

  1. (转)MyBatis+MySQL 返回插入的主键ID

    MyBatis+MySQL 返回插入的主键ID 需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值. 方法:在mapper中指定keyProperty属性,示例如 ...

  2. mybatis+mysql返回插入的主键,参数只是提供部分参数

    mybatis+mysql返回插入的主键,参数只是提供部分参数 <insert id="insertByChannelIdOpenid" useGeneratedKeys=& ...

  3. MyBatis+MySQL 返回插入的主键ID

    需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值. 方法:在mapper中指定keyProperty属性,示例如下: <insert id="i ...

  4. Mybatis返回插入的主键

    在使用MyBatis做持久层时,insert语句默认是不返回记录的主键值,而是返回插入的记录条数:如果业务层需要得到记录的主键时,可以通过配置的方式来完成这个功能 情景一:针对自增主键的表,在插入时不 ...

  5. Mybatis 返回插入的主键

    业务中,会遇到这样的问题,就是感觉返回的主键,插入作为其他表的外键. 那么问题来了,如何去实现,其实方法比较简单,这里就是重点记录下,会出现的误区. 用自动生成sql工具的话,加上下面这句话 < ...

  6. MyBatis返回插入的主键ID(Mysql数据库)

    1.Java代码: 1.1 entity类: User.java public class User { private int userId; private String userName; pr ...

  7. mybatis MySQL返回插入的主键ID,oracle不行

    <insertid=“doSomething"parameterType="map"useGeneratedKeys="true"keyProp ...

  8. MyBatis + MySQL返回插入的主键id

    这是最近在实现perfect-ssm中的一个功能时碰到的一个小问题,觉得需要记录一下,向MySQL数据库中插入一条记录后,需要获取此条记录的id值,以生成对应的key值存入到redis中,id为自增i ...

  9. mybatis oracle insert 返回新增的主键值

    <insert id="insertVmsTemplatePlayItem" parameterType="VmsTemplatePlayItem"> ...

随机推荐

  1. shell expr的用法

    root@tcx4440-03:~# var=$var+1root@tcx4440-03:~# echo $var3+1 要想达到预期结果,用下列三种方法: (1)let "var+=1&q ...

  2. js常用插件

    1.jQuery Shortcuts 是个超轻量级的方法,使用 jQuery 来绑定快捷键(热键). 2.Underscore封装了常用的JavaScript对象操作方法,用于提高开发效率. 3.Kn ...

  3. 解决vs2015使用fopen、fprintf等函数报错的问题

    出现错误提示: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable ...

  4. [IOS Delegate和协议]

    转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/25655443 作者:小马 代理和协议的语法这里不赘述,自己查资料. 这个demo的 ...

  5. 数字证书文件格式(cer和pfx)的区别

    作为文件形式存在的证书一般有这几种格式: 1.带有私钥的证书 由Public Key Cryptography Standards #12,PKCS#12标准定义,包含了公钥和私钥的二进制格式的证书形 ...

  6. C#获取本机IP且过滤非真实网卡(如虚拟机网卡)

    参考了网上的文章,具体地址不记得了. 下面的方法可以过滤掉虚拟机的网卡等无效网卡,进而只留下真实的网卡. using System; using System.Collections.Generic; ...

  7. C#用UPnP穿透内网

    参考了网上的一篇文章,由于时间长了,具体地址不知道了. 引入了一个DLL: Interop.NATUPNPLib.dll,实现穿透局域网,进行Socket通信. using System; using ...

  8. Activity启动模式 及 Intent Flags 与 栈 的关联分析

     http://blog.csdn.net/vipzjyno1/article/details/25463457    Android启动模式Flags栈Task   目录(?)[+] 什么是栈 栈 ...

  9. Common Pitfalls In Machine Learning Projects

    Common Pitfalls In Machine Learning Projects In a recent presentation, Ben Hamner described the comm ...

  10. WPF 动态布局Grid

    //开启线程加载 Action a = () => { ; ; var path = "../../face_img/"; var files = Directory.Get ...