使用Oracle的序列號
先查詢出下一個序列號,且會自動注入到參數中的指定屬性上(本例中的id屬性), 插入完成后, controller中的user對象的id屬性也有值了
<insert id="addUser" parameterType="user" > <!-- keyPRoperty: 將序列號設置到user對象中,且在controller中可以使用 --> <selectKey keyProperty="id" order="BEFORE" resultType="string"> SELECT seq_changez_user.nextval id from dual </selectKey> insert into temp_changez_user (id, username) values(#{id}, #{username}) </insert>
新聞熱點
疑難解答