XML:

<insert id="addUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">

注解:

@Insert("your sql goes here")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int insert(FileAttachment fileAttachment) throws Exception;

说明:

返回的主键值会直接赋值到实体,而不是方法体的返回值。

 

参考:

https://stackoverflow.com/questions/12103606/get-the-id-of-last-inserted-record-in-mybatis

相关文章:

  • 2021-07-27
  • 2022-12-23
  • 2021-07-28
  • 2021-10-02
  • 2021-07-19
  • 2022-02-12
猜你喜欢
  • 2021-11-26
  • 2022-12-23
  • 2021-08-26
  • 2022-02-14
  • 2021-07-25
  • 2022-02-01
相关资源
相似解决方案