用mybatis更新数据,当数据为0时,无法更新

在bean中,count是long类型:

private Long count;

需求就是利用下面的更新语句更新bills表中的count和amout

<update id="updateBills" parameterType="map" >
  UPDATE bills 
  <set>
  <if test="count != null and count != ''">
     count = #{count,jdbcType=NUMERIC},
  </if>
  <if test="amount != null and amount != ''">
     amount = #{amount,jdbcType=NUMERIC},
  </if>
            update_time = now() 
</set> 
    where id = #{id,jdbcType=VARCHAR} 
    and 
    bill_date = to_date(#{billDate,jdbcType=DATE},'yyyy-MM-dd'))
</update>

问题出现了:

Map<Object, Object> updateMap = new HashMap<Object, Object>();
updateMap .put("id", bills.getId());
updateMap .put("billDate",dateString);
updateMap .put("amount", bills.getAmount());
updateMap .put("count",bills.getCount());

billsDao.updateBills(updateMap);

当bills.getCount()等于0时,就是无法更新,所以我不得不做了以下判断,然后就有效的解决了这个问题,但是因为什么呢?我也不知道!

Map<Object, Object> updateMap = new HashMap<Object, Object>();
updateMap .put("id", bills.getId());
updateMap .put("billDate",dateString);
updateMap .put("amount", bills.getAmount());
if(0 == bills.getHisCount()){
    updateMap .put("count",0);
}else{
    updateMap .put("count",bills.getCount());
}
billsDao.updateBills(updateMap);

你可能感兴趣的:(数据,mybatis)