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语句是否有问题