MyBatis插入时候获取自增主键方法
2016-08-20 15:14
183 查看
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;
相关文章推荐
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis 3.2.6插入时候获取自增主键方法有二
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis 3.2.6插入时候获取自增主键方法有二
- MyBatis 3.2.6插入时候获取自增主键方法
- mybatis获取mysql插入的自增主键配置方法
- 使用mybatis的insert语句插入数据的时候,获取插入数据的主键id
- MyBatis 插入时候获取自增主键(1:写sql。2:注解@generatedvalue)
- MyBatis插入时获取自增主键方法
- MyBatis插入及查询获取自增主键二选一的方法
- mybatis获取插入的语句主键(自增主键)