search

Home  >  Q&A  >  body text

java - mybatis 插入数据到oracle,id无法用selectkey获取到数据


如图,所示,id判断是不是null的时候,竟然认为id=null,结果sql语句就变成
INSERT INTO core_tzt_product ( product_name, product_type, product_price, crasr_code, period_days, buy_type, start_date, end_date ) values ( ?, ?, ?, ?, ?, ?, ?, ? ) ,
但是如果我把id判断是不是null的if去掉,则可以新增成功。代码如下


,有点搞不清楚,这是mybatis的bug吗,还是我哪里有弄错

阿神阿神2802 days ago428

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:52:29

    SelectKey needs to pay attention to the order attribute. In databases like MySQL that support automatic growth, order needs to be set to after to get the correct value.

    reply
    0
  • Cancelreply