oracle 数据库 mybatis 框架。insert 操作需要返回一个自增的主键 id 到 controller 层

2019-08-12 18:27:44 +08:00
 mart1nN

百度了很多方法都是 selectKey 标签操作,后台确实检测到了 selectKey 中的查询。但是数据似乎不能返回到 controller

大概的 sql 是这样的

<insert id = "insertCustomer" parameterType = "com.xxx.Customer">
  insert into custom (customerId, ...)
  values (customerId.Nextval, ...)
  <selectKey returnTpye = “ java.lang.Integer ” order = “ after ”>
    select customerId.Currval from dual
  </selectKey>
</insert>

其他层的方法返回值都是 Integer

所以目前的解决办法只能插入操作和查询操作分开执行

师傅们有什么高见。或者说有其他好的方法吗

1226 次点击
所在节点    问与答
1 条回复
Raymon111111
2019-08-12 19:22:43 +08:00
搜一下 useGeneratedKeys

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/591272

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX