1、获得插入语句执行之后的自增主键
<insert id="insertUser" parameterType="com.mybatis.po.User"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer"> select LAST_INSERT_ID() </selectKey> insert into user(id,username,birthday,sex,address) values(#{id},#{username},#{birthday},#{sex},#{address}) </insert>
2、获得插入语句执行之前的非自增主键
<insert id="insertUser" parameterType="com.mybatis.po.User"> insert into user(id,username,birthday,sex,address) values(#{id},#{username},#{birthday},#{sex},#{address}) <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer"> select uuid() </selectKey> </insert>
时间: 2024-10-13 14:09:53