Mybatis oracle inserts data and returns the primary key id

 

<insert id="add" parameterType="XXX.YYY.User">
    <selectKey keyProperty="id" resultType="String" order="BEFORE">
        select sys_guid() from dual 
    </selectKey>
    insert into T_USER(id, name, age) values(#{id}, #{name}, #{age})
</insert

Note: The return value of the mapper interface is still the number of records successfully inserted, but the difference is that the primary key value has been assigned to the id of the domain model entity.

 

Guess you like

Origin blog.csdn.net/ShenDaiSun/article/details/93215841