mybatis mysql 主键自增长
MyBatis 插入时候获取自增主键
方法有二
方法1-1:
<insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
insert into person(name,pswd) values(#{name},#{pswd})
</insert>
方法1-2:
<insert id="insert" parameterType="Person">
<selectKey keyProperty="id" resultType="long">
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
采用注解方式,经测试需要给主键设置自增长。
相关推荐
xiuyangsong 2020-11-16
Nishinoshou 2020-11-09
jimgreatly 2020-09-01
dongxurr 2020-08-18
Dullonjiang 2020-08-15
Dullonjiang 2020-08-11
Dullonjiang 2020-08-09
dongxurr 2020-08-08
yunzhonmghe 2020-08-07
jimgreatly 2020-08-03
Dullonjiang 2020-07-30
jimgreatly 2020-07-27
liqiancao 2020-07-26
xiuyangsong 2020-07-26
dongxurr 2020-07-26
mcvsyy 2020-07-26
helloxusir 2020-07-25
牧场SZShepherd 2020-07-20