ITPub博客

首页 > IT职业 > IT生活 > mybatis连接mysql获取自增的主键

mybatis连接mysql获取自增的主键

IT生活 作者:lizhm 时间:2021-09-09 09:01:27 0 删除 编辑

第一种方式:、
使用mysql的函数:last_insert_id()


                select LAST_INSERT_ID()
           

           insert into User(username,password) values(#{username}, #{password})

第二种方式:



insert into User(username,password) values(#{username}, #{password})

第二种方式比第一种方式要简单,因此建议大家使用。
另外,获取非自增主键的方式:
uuid则使用mysql的uuid()函数
oracle则使用序列,使用nextval()函数

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4614/viewspace-2798705/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-13

  • 博文量
    78
  • 访问量
    755