MyBatis插入时候获取自增主键方法
2017-04-10 16:23
295 查看
SelectKey在Mybatis中是为了解决Insert数据时数据库不支持主键自动生成的问题,useGeneratedKeys是支持主键自增时使用的方法
方法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;
方法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 3.2.6插入时候获取自增主键方法有二
- MyBatis 3.2.6插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis 3.2.6插入时候获取自增主键方法有二
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入时候获取自增主键方法
- MyBatis插入及查询获取自增主键二选一的方法
- 使用mybatis的insert语句插入数据的时候,获取插入数据的主键id
- MyBatis 插入时候获取自增主键(1:写sql。2:注解@generatedvalue)
- MyBatis插入时获取自增主键方法
- mybatis获取mysql插入的自增主键配置方法
- 使用标量值函数作为主键自增值的时候,动软代码生成器的插入方法需要去掉主键的参数。