mybatis中Oracle及mysql插入时自动生成主键以及返回主键

mysql的方式:

方式一:useGeneratedKeys="true" keyProperty="id"

方式二:

  <selectKey keyProperty="studentID" resultType="String" order="BEFORE">

    select nextval('student')

  </selectKey>

Oracle的方式:

<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
  SELECT common_seq.CURRVAL AS VALUE FROM DUAL
</selectKey>

其中<selectKey >的order 属性值    可以设成BEFORE 或者AFTER,如果设为BEFORE,那它会先选择主键,然后设置keyProperty,再执行insert语句;如果设为AFTER,它就先运行insert 语句再运行selectKey 语句

 

猜你喜欢

转载自www.cnblogs.com/sun-flower1314/p/11713776.html
今日推荐