mybatis插入oracle的序列号

使用oracle的序列号

先查询出下一个序列号,且会自动注入到参数中的指定属性上(本例中的id属性), 插入完成后, controller中的user对象的id属性也有值了

  1. <insert id="addUser" parameterType="user" >
  2. <!-- keyProperty: 将序列号设置到user对象中,且在controller中可以使用 -->
  3. <selectKey keyProperty="id" order="BEFORE" resultType="string">
  4. SELECT seq_changez_user.nextval id from dual
  5. </selectKey>
  6. insert into temp_changez_user (id, username) values(#{id}, #{username})
  7. </insert>

注意selectKey中的resultType的值,他决定了序列返回值的类型,项目中根据实际情况修改。

猜你喜欢

转载自blog.csdn.net/gaoshan12345678910/article/details/80974264