mybatis学习笔记2

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>
原文地址:https://www.cnblogs.com/mrluotong/p/5854687.html