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