记一次insert into on duplicate key update返回主键的问题
- 2020-09-01 11:00:00
- admin 原创
- 3835
记一次insert into on duplicate key update返回主键的问题:
1、我的mybatis的配如下:
<insert id="save" parameterType="com.aumall.modules.finance.lsxz.entity.LsxzCard" useGeneratedKeys="true" keyProperty="lsxzCardId" > insert into au_lsxz_card ( `card`, `type` ) values ( #{card}, #{type} ) ON DUPLICATE KEY UPDATE <trim prefix="" suffixOverrides=","> <if test="type!=null">`type`=#{type},</if> </trim> </insert>2、这个一直不返回主键,是因为有索引,直接进行了更新,而且没有更新的结果,
当没有更新结果的时候,是不返回主键的
修改后的代码如下(必须有更新结果才会返回主键):
<insert id="save" parameterType="com.aumall.modules.finance.lsxz.entity.LsxzCard" useGeneratedKeys="true" keyProperty="lsxzCardId" > insert into au_lsxz_card ( `card`, `type` ) values ( #{card}, #{type} ) ON DUPLICATE KEY UPDATE <trim prefix="" suffixOverrides=","> <if test="type!=null">`type`=#{type},</if> update_time=now() </trim> </insert>
发表评论
文章分类
联系方式
联系人: | 郑州-小万 |
---|---|
电话: | 13803993919 |
Email: | 1027060531@qq.com |
QQ: | 1027060531 |
网址: | www.wanhejia.com |
Update Required
To play the media you will need to either update your browser to a recent version or update your Flash plugin.