saveAll支持有id则更新和无id则插入

This commit is contained in:
抓蛙师
2021-08-25 20:24:35 +08:00
parent 8ffe111086
commit 545f0bd4b0
2 changed files with 33 additions and 3 deletions

View File

@ -39,8 +39,13 @@ public class TestBatchController extends BaseController {
// @DataSource(DataSourceType.SLAVE)
public AjaxResult<Void> add() {
List<TestDemo> list = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
list.add(new TestDemo().setOrderNum(-1L).setTestKey("批量新增").setValue("测试新增"));
for (int i = 0; i < 10; i++) {
TestDemo testDemo = new TestDemo();
if (i % 2 == 0) {
list.add(testDemo.setId((long) i + 1).setTestKey("批量更新").setValue("批量更新"));
} else {
list.add(testDemo.setOrderNum(-1L).setTestKey("批量新增").setValue("测试新增"));
}
}
return toAjax(iTestDemoService.saveAll(list) ? 1 : 0);
}