当前使用版本

mybatis-plus-boot-starter 3.5.2

重现步骤

参考 https://github.com/wlnirvana/mp-bug

具体而言,使用saveBatch时,这个batch里的对象虽然生成了id、存入了数据库,但这些id无法被正确填入java对象中。这个回复给出了一个例子。

Comment From: qmdx

你提供的案例并不是 auto 模式

Comment From: wlnirvana

你提供的案例并不是 auto 模式

auto模式不是这样设置的吗?请问应该如何配置呀?

https://github.com/wlnirvana/mp-bug/blob/9c8027bf3a02de2cdb67b5ba675e753f4950f660/src/main/resources/application.properties#L4

Comment From: melon-huang

同学,你数据库的id没有设置自增。 https://github.com/wlnirvana/mp-bug/blob/master/src/main/resources/schema.sql#L4

Comment From: wlnirvana

之前确实没有设置自增ID。不过设置了之后,saveBatch仍然不能将生成的ID正确返回,仅第一个元素的ID得到了更新。例如,访问http://localhost:9000/saveBatch 返回结果类似下面。虽然插入了3条记录,但是后两条的id都没有被设置进相应的对象里。

[
   9,
   null,
   null
]

而访问http://localhost:9000/saveOneByOne 则会返回如下的预期结果:

[
   9,
   10,
   11
]

Comment From: wavecao

之前确实没有设置自增ID。不过设置了之后,saveBatch仍然不能将生成的ID正确返回,仅第一个元素的ID得到了更新。例如,访问http://localhost:9000/saveBatch 返回结果类似下面。虽然插入了3条记录,但是后两条的id都没有被设置进相应的对象里。

json [ 9, null, null ]

而访问http://localhost:9000/saveOneByOne 则会返回如下的预期结果:

json [ 9, 10, 11 ]

请问现在找到问题没?解决方法是什么?