- 在mysql中:
<insert id=”add” useGeneratedKeys=”true” keyProperty=”id” parameterType=”Auth”>
insert into t_user (id, user_name) values(#{id},#{username})
</insert>
利用useGenerateKeys=true来实现
2.在oracle中
<insert id=”insert” useGeneratedKeys=”false” keyProperty=”id” parameterType=”User”>
<selectKey resultType=”String” keyProperty=”id” order=”BEFORE”>
select seq_user.nextval as id from dual
</selectKey>
insert into t_user (id, user_name) values(#{id},#{username})
</insert>
或
<insert id=”insert” useGeneratedKeys=”false” keyProperty=”id” parameterType=”User”>
insert into t_user (id, user_name) values(seq_user.nextval,#{username})
</insert>
oracle中的自增由序列来实现