MyBatis插入时候获取自增主键方法
2015-09-22 14:36
429 查看
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;
相关文章推荐
- word2vec训练参数说明
- UEditor在线编辑器配置及注意事项
- linux 相关知识
- 使用Docker部署iRedmail
- SecureCRT7.3下载安装详细步骤
- chart图形绑定数据
- POJ 3321 Apple Tree(dfs序 + 树状数组)
- windows和linux环境中分别如何用C语言获得本机IP地址?
- 眉目传情之匠心独运的kfifo
- C++面试常见问题
- 第三方分享(新浪,微信,QQ)
- NSUserDefaults保存用户名和密码
- Debian/Ubuntu下安装GeoIP
- java.util.concurrent之CountDownLatch
- Linux c 下代码调试
- [Leetcode]Single Number II
- VC2005创建和加载.DLL文件的方法
- 为什么需要内存屏障
- Android View的ScrollBar
- android shape的使用