postgresql實現插入數據返回當前的主鍵ID


  <insert id="addUser" parameterType="com.liupan.user">
         <selectKey keyProperty="id" resultType="java.lang.Integer" order="AFTER">
             select currval('user_user_id_seq') as id
         </selectKey>
         insert into USER(USER_NAME,PASSWORD,CREATE_TIME) 
         values(#{userId},#{password},#{createTime,typeHandler=dateTimeTypeHandler})
   </insert>

除了currval()函數外,還有nextval()函數,但是nextval()函數會導致postgresql的主鍵加1,所以不能用在這種情況下


免責聲明!

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



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