MyBatis插入时候获取自增主键方法
2015-11-11 01:06
387 查看
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;
相关文章推荐
- Android studio Json 转换对象 Bean 插件 GsonFormat 的安装以及使用
- Hibernate(四)——缓存策略+lazy
- pca+lda
- 【JavaScript知识点十】javascript DOM基本操作
- Cocoa开发——PIPE通讯框架
- 10006---JavaWeb基础--HttpServletResponse
- 2016年潜力股
- samba服务配置
- Windows平台Java开发环境的搭建
- opencv reshape
- 关于Unity3D中的版本管理
- 2015 Changchun F
- Bounds边界框
- Hibernate(三)——框架中的关系映射
- dos启动mysql
- Android极光推送
- 关于状态机的思想问题
- '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error
- EditorUtility
- Android天氣預報的開發分析