小编Unk*_*200的帖子

使用 MyBatis Annotation Spring Boot 检索生成的 ID

我正在努力学习MyBatis。使用注释插入语句后如何获取自动生成的 ID @Insert

我的代码示例:

@Insert("INSERT INTO user(name, mobile, password) VALUES(#{name}, #{mobile}, #{password})")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
Long insertUser(User user);
Run Code Online (Sandbox Code Playgroud)

我想获取生成的 id 作为插入方法的返回。

intellij-idea mybatis spring-boot spring-mybatis

2
推荐指数
1
解决办法
3780
查看次数