myBatis oracle 与mysql自增问题

mysql

<insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
        insert into person(name,pswd) values(#{name},#{pswd})
    </insert>

<insert id="insert" parameterType="Person">
        <selectKey keyProperty="id" resultType="long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into person(name,pswd) values(#{name},#{pswd})
    </insert>

oracle

CREATE SEQUENCE  "SEQ_M_USER"

MINVALUE 1

MAXVALUE 9999999999999999999999999999

INCREMENT BY 1 START WITH 501 CACHE 20 ORDER  NOCYCLE ;

1.先通过sequence查出来id,再insert

<insert id=”add” useGeneratedKeys=”false” keyProperty=”id” parameterType=”Person”>
<selectKey resultType=”String” keyProperty=”id” order=”BEFORE”>
select yoursequence.nextval as id from dual
</selectKey>
insert into Person (id,user_id, user_name) values(#{id},#{userid},#{username})
</insert>

2.直接insertsequence.nextval,如下

<insert id=”add” useGeneratedKeys=”false” keyProperty=”id” parameterType=”Person”>
insert into Person (id,user_id, user_name) values(yoursequence.nextval,#{userid},#{username})
</insert>
上一篇:Spring基于注解和XML混合方式的使用


下一篇:在RichTextBox控件中添加图片和文字