首页 > 其他 > 详细

keyProperty="id" 和useGeneratedKeys="true"作用

时间:2019-01-16 14:55:13      阅读:883      评论:0      收藏:0      [点我收藏+]

在使用mybatis时,常常会出现这种需求:
当主键id是自增的情况下,添加一条记录的同时,其主键id是不能使用的,当我们取出主键id的值发现id为null,但是有时我们需要该主键,这时我们该如何处理呢?
这时我们只需要在其对应xxxmapper.xml中加入以下属性即可:
useGeneratedKeys=”true” keyProperty=”id”

 1 <insert id="insertSelective" parameterType="com.xxx.dataobject.UserDo" keyProperty="id" useGeneratedKeys="true">

2 ............

3 </insert> 

 主要是在主键是自增的情况下,添加成功后可以直接使用主键值,其中keyProperty的值是对象的属性值不是数据库表中的字段名

 

keyProperty="id" 和useGeneratedKeys="true"作用

原文:https://www.cnblogs.com/zenghuilong/p/10276831.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!