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>

 

posted on 2016-09-08 22:11  Lightt  阅读(206)  评论(0编辑  收藏  举报