MyBatis 3.2.6插入时候获取自增主键方法
2015-09-07 12:46
375 查看
MyBatis 3.2.6插入时候获取自增主键方法有二
以MySQL5.5为例:
方法1:
<insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
insert into person(name,pswd) values(#{name},#{pswd})
</insert>
方法2:
<insert id="insert" parameterType="Person">
<selectKey keyProperty="id" resultType="long">
select LAST_INSERT_ID()
</selectKey>
insert into person(name,pswd) values(#{name},#{pswd})
</insert>
插入前实体id属性为0;
插入后实体id属性为保存后自增的id;
以MySQL5.5为例:
方法1:
<insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
insert into person(name,pswd) values(#{name},#{pswd})
</insert>
方法2:
<insert id="insert" parameterType="Person">
<selectKey keyProperty="id" resultType="long">
select LAST_INSERT_ID()
</selectKey>
insert into person(name,pswd) values(#{name},#{pswd})
</insert>
插入前实体id属性为0;
插入后实体id属性为保存后自增的id;
相关文章推荐
- AWK简介
- ubuntu文件拷贝的问题
- C# 的@是可定义Unicode变量的
- hdu 2825 Wireless Password (ac自动机+状态压缩dp)
- 留住你的用户:8款第三方移动推送服务
- 一道面试题
- 菜鸟启航:UIButton基本操作
- Algorithms—39.Combination Sum
- 股权转让所得个人所得税管理办法(试行)
- [DS][Hash][PAT][Hashing Hard Version]
- 未来的十倍股在哪里
- 代码是大的工程
- 腾迅不敢发放的一个QQ号码
- 图片下载和保存
- 给敏捷团队中的架构师的10个建议
- 编程之美----3.5最短摘要的生成
- Delphi类里面的方法和类型定义不影响创建实例的大小
- hadoop笔记1-MR执行过程
- jQuery实现简单下拉导航效果
- google.com 还会换IP