java - mybatis update失败却不报错

查看:1369
本文介绍了java - mybatis update失败却不报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

1.更新时返回值为0,影响行数为0。不知道为什么,自己尝试在数据库管理系统执行sql语句是有作用的。也不报错,求大神!
2.代码如下:
1)Mapper.xml


<update id="updateByPrimaryKeySelective" parameterType="com.lianhehui.pojo.CardOwn">
    update cardown
    <set>
      <if test="memberid != null">
        memberId = #{memberid,jdbcType=INTEGER},
      </if>
      <if test="cardid != null">
        cardId = #{cardid,jdbcType=INTEGER},
      </if>
      <if test="discount != null">
        discount = #{discount,jdbcType=REAL},
      </if>
      <if test="balance != null">
        balance = #{balance,jdbcType=REAL},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=CHAR},
      </if>
    </set>
    where cardOwnId = #{cardownid,jdbcType=INTEGER}
  </update>

2)Service(Dao层就省略了)

@Override
    public int topUpToCard(CardOwn cardOwn) {
        // TODO Auto-generated method stub
        return cardOwnDao.updateByPrimaryKeySelective(cardOwn);
    }

3)Controller内

CardOwn cardOwn = new CardOwn();
cardOwn.setCardid(cardOwnId);
cardOwn.setBalance(balance+amount);
            
int success = memberService.topUpToCard(cardOwn);
if (success == 0) {
    System.out.println("充值失败");
}else {
    System.out.println("充值成功");
}

解决方案

不知道你有没有配置控制台输出 发出的sql语句的配置 如果配置了可以看一下发出的sql语句是否有问题

这篇关于java - mybatis update失败却不报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆