标签:
引用自:https://hacpai.com/article/1405392025960
mysql、sqlserver等数据库本身带有主键自增长像auto_increment的功能可以直接使用
useGeneratedKeys=”true”来实现,比如下面的配置
<insert id=”add” useGeneratedKeys=”true” keyProperty=”id” parameterType=”Auth”>
insert into s_user_auth (id,user_id, user_name) values(#{id},#{userid},#{username})
</insert>
而oracle则不行,oracle主键自增长是通过sequence实现的,所以这种方式就不可以了,需要使用:
1.先通过sequence查出来id,再insert
<insert id=”add” useGeneratedKeys=”false” keyProperty=”id” parameterType=”Auth”>
<selectKey resultType=”String” keyProperty=”id” order=”BEFORE”>
select yoursequence.nextval as id from dual
</selectKey>
insert into s_user_auth (id,user_id, user_name) values(#{id},#{userid},#{username})
</insert>
2.直接insertsequence.nextval,如下
<insert id=”add” useGeneratedKeys=”false” keyProperty=”id” parameterType=”Auth”>
insert into s_user_auth (id,user_id, user_name) values(yoursequence.nextval,#{userid},#{username})
</insert>
标签:
原文地址:http://www.cnblogs.com/zhangmu126/p/5234180.html