mybatis-flex / mybatis-flex

mybatis-flex is an elegant Mybatis Enhancement Framework

Home Page:https://mybatis-flex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Db.insertBatchWithFirstRowColumns方法自动填充主键错误

TianXinX opened this issue · comments

按代码注释的描述该方法会自动填充主键
image

但图片中标记的部分会把rows中自动填充的主键删除,导致插入时报错
image

麻烦给出使用的代码,以及错误信息。

问题一:不能自动填充主键字段

建表语句

CREATE TABLE test(
    id   VARCHAR(20) PRIMARY KEY,
    name VARCHAR(20),
    age  INTEGER
);

测试代码

@SpringBootTest
public class DbRowTest {

    @Test
    public void testDbInsertBatchWithFirstRowColumns() {
        List<Row> rows = new ArrayList<>();

        Row row1 = Row.ofKey(RowKey.SNOW_FLAKE_ID);
        row1.put("name", "张三");
        row1.put("age", 20);
        rows.add(row1);

        Row row2 = Row.ofKey(RowKey.SNOW_FLAKE_ID);
        row2.put("age", 30);
        row2.put("name", "李四");
        rows.add(row2);

        Db.insertBatchWithFirstRowColumns("test", rows);
    }
}

错误信息

image

问题二:列顺序没有与第一条保持一致

测试代码

@SpringBootTest
public class DbRowTest {

    @Test
    public void testDbInsertBatchWithFirstRowColumns() {
        List<Row> rows = new ArrayList<>();

        Row row1 = new Row();
        row1.put("id", "1");
        row1.put("name", "张三");
        row1.put("age", 20);
        rows.add(row1);

        Row row2 = new Row();
        row2.put("age", 30);
        row2.put("id", "2");
        row2.put("name", "李四");
        rows.add(row2);

        Db.insertBatchWithFirstRowColumns("test", rows);
    }
}

错误信息

image