Mybatis插入后返回主鍵


<insert id="add" parameterType="vo.Category">

<selectKey resultType="java.lang.Short" order="AFTER" keyProperty="id">

SELECT LAST_INSERT_ID()

</selectKey>

insert into category (name_zh, parent_id,

show_order, delete_status, description

)

values (#{nameZh,jdbcType=VARCHAR},

#{parentId,jdbcType=SMALLINT},

#{showOrder,jdbcType=SMALLINT},

#{deleteStatus,jdbcType=BIT},

#{description,jdbcType=VARCHAR}

)

</insert>


在插入操作完成之后,參數category的id屬性就已經被賦值了

執行完mapper.insert(category);獲取插入返回的主鍵用category.getId()就可以了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM