V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
mart1nN
V2EX  ›  问与答

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

  •  
  •   mart1nN · 2019-08-12 18:27:44 +08:00 · 1205 次点击
    这是一个创建于 1690 天前的主题,其中的信息可能已经有所发展或是发生改变。

    百度了很多方法都是 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

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

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

    1 条回复    2019-08-12 19:22:43 +08:00
    Raymon111111
        1
    Raymon111111  
       2019-08-12 19:22:43 +08:00
    搜一下 useGeneratedKeys
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3136 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:37 · PVG 20:37 · LAX 05:37 · JFK 08:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.