MyBatis插入语句返回主键值

插入语句xml代码:

<insert id="insertUser" parameterType="com.spring.mybatis.po.User"> 
     
     <!--selectKey获取插入的id值
         keyProperty="id":将查询到主键设置到对象中的某个属性上
         order="AFTER":执行查询主键ID值的顺AFTER:执行之后获取
         resultType:获取返回结果类型(包装类)
         SELECT LAST_INSERT_ID():MySql获取自增主键的函数
       
     <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
         SELECT LAST_INSERT_ID()
     </selectKey>
     -->
     <!--  非自增
     <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Integer">
         SELECT UUID()
     </selectKey>
     -->
     <!-- ORACLE -->
     <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Integer">
         SELECT 序列名.nextval()
     </selectKey>
     
  INSERT INTO USER(username,birthday,sex,address) VALUE(#{username},#{birthday},#{sex},#{address})
  </insert>

其他引文:http://blog.csdn.net/blueheart20/article/details/25631393

原文地址:https://www.cnblogs.com/zlay0701/p/5259735.html