mybatis insert 返回主鍵

  • 插入後需要返回自增的主鍵,以便後續的操作。
<insert id="insert" parameterType="Student" useGeneratedKeys="true" keyProperty="id">
  insert into Student(name, age) values(#{name}, #{age})
</insert>
  • 在insert 語句上添加了useGeneratedKeys="true" keyProperty="id" ,這樣插入後會返回主鍵,主鍵set到入參的對象。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章