mybatis+pgsql 执行 insert 和 update 之后返回 id
資深大佬 : jiobanma 3
看到网上是这么写的
<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>
tbl_user_pid_seq 是一个序列,但是自己的库 id 没有序列,是自己写了一个 next_id 的函数。 并且因为需要,mybatis 的 parameterType 也不是一个 entity,而是一个 Map 这种时候 xml 该怎么写才能拿到 insert 之后的 id
大佬有話說 (7)