<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,所以不能用在这种情况下