mybatis 中 insertSelective(example) 语句默认返回并不是 插入记录的主键。

我们可以考虑插入记录主键不直接作为 函数的返回值, 而是体现在改变函数参数 "example", 使其主键等于插入记录的主键。

在insertSelective xml定义中,加入以下代码:

<selectKey resultType="Integer" keyProperty="id" >
  SELECT last_insert_id() as id;
</selectKey>

这样就完成了对与参数改变。

 

注: 该方法只适用于 mysql 数据库!

 

相关文章:

  • 2021-07-27
  • 2022-12-23
  • 2021-11-26
  • 2021-07-28
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-02-14
  • 2021-12-16
  • 2022-02-01
  • 2021-07-25
相关资源
相似解决方案