MyBatis 3.2.6插入时候获取自增主键方法有二
2015-12-31 15:33
387 查看
以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;
文章出自:http://www.linuxidc.com/Linux/2014-03/98965.htm
方法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;
文章出自:http://www.linuxidc.com/Linux/2014-03/98965.htm
相关文章推荐
- 存储对象到文件
- Makefile中的export
- spfile详解
- Zoho Books的库存功能介绍
- DWR入门实例(二)
- java反射
- Android的性能优化
- 中国主要咨询类型领域发展指数规模水平信息
- HOG
- 序列化--关于 Java 对象序列化您不知道的 5 件事
- 前端颜色版不错的工具 收藏掉
- WordPress中获取所使用的模板的页面ID的简单方法
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy DP
- 动手验证<<深入理解angularjs中的scope>>
- iOS 事件处理机制与图像渲染过程
- LeetCode - Edit Distance
- Android加载Gif图片的一般方法:Movie实现
- Macbook Pro Retina实现OSX10.10 Yosemite 和Win7双系统(Win7多分区)
- studio好用的插件
- Swift的基础,操作符,字符串和集合类型