需求:使用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
查看更多关于MyBatis+MySQL返回插入的主键ID的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did97142