MyBatis在MySql中增加数据后返回主键

来源:互联网 发布:淘宝联盟网站推广审核 编辑:程序博客网 时间:2024/06/06 11:41

在使用MyBatis过程中,发现增加数据后,返回的是增加的条数,得不到主键,影响以后的开发。

如何控制在增加数据后获取到主键呢?


<!-- 新增项目信息 -->
<insert id="insertTbProject" parameterType="TbProject" useGeneratedKeys="true" keyProperty="id">
insert into tb_project
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="projectname != null" >
projectname,
</if>
<if test="type != null" >
type,
</if>

....


添加该属性后,在后台添加完成后,对象的id会自动获取到,但返回的仍是增加的条数。

1 0
原创粉丝点击