标签:ted use _id value gen ati 保存 key last
MyBatis 插入时候获取自增主键
方法有二
方法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;
@generatedvalue
MyBatis 插入时候获取自增主键(1:写sql。2:注解@generatedvalue)
标签:ted use _id value gen ati 保存 key last
原文地址:http://www.cnblogs.com/CESC4/p/7095870.html