您好,欢迎访问一九零五行业门户网

MyBatis+MySQL 返回插入的主键ID

需求:使用mybatis往mysql数据库中插入一条记录后,需要返回该条记录的自增主键。 方法:在mapper中指定keyproperty属性,示例如下: insert id=insertandgetid usegeneratedkeys=true keyproperty=userid parametertype=com.chenzhou.mybatis.userinsert in
需求:使用mybatis往mysql数据库中插入一条记录后,需要返回该条记录的自增主键值。
方法:在mapper中指定keyproperty属性,示例如下:
insert into user(username,password,comment) values(#{username},#{password},#{comment})
如上所示,我们在insert中指定了keyproperty=userid,其中userid代表插入的user对象的主键属性。
user.java
其它类似信息

推荐信息