SpringBoot + Mybatis 获取插入后的ID

方式1

@SelectKey(statement="select LAST_INSERT_ID()", keyProperty="id", before=false, resultType=int.class)
public int insert(GenTemplate entity);

方式2



    //注意keyProperty 与类中的id属性名称要一致

    
        //此处为mysql的函数
        select LAST_INSERT_ID()
    
    insert into table_name
    (...)
    values
    (...)

你可能感兴趣的:(SpringBoot,mybatis,spring,boot,java)