mybatis postgresql insert后返回自增id


在使用mybatis + postgresql,我們有時在插入數據時需要返回自增id的值,此時在插入時,可以按照以下例子來編寫mapper文件

<insert id="insertUser">
    <selectKey resultType="int"  order="AFTER" keyProperty="pid" >
        SELECT currval('tbl_user_pid_seq'::regclass) AS pid
    </selectKey>
    insert into tbl_user(name, age) values(#{name}, #{age})
</insert>

  


免責聲明!

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



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