<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,所以不能用在這種情況下