MyBatis 插入时候获取自增主键

方法有二

方法1-1:

    <insert >
        insert into person(name,pswd) values(#{name},#{pswd})
    </insert>

 

方法1-2:

    <insert >
            select LAST_INSERT_ID()
        </selectKey>
        insert into person(name,pswd) values(#{name},#{pswd})
    </insert>

 

方法2:

@Id

@GeneratedValue(strategy=GenerationType.IDENTITY)

int id;

 

insert插入后可以通过getId()获取id

 

 

@generatedvalue

相关文章:

  • 2022-12-23
  • 2021-10-07
  • 2021-09-12
  • 2021-08-15
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2022-12-23
相关资源
相似解决方案