关于数据库字段类型decimal对应Java的BigDecimal类型问题

问题: 当改为空或0时,提交后时无法更改,仍显示改前数据!

 

原因:在mybatis映射文件中<update>方法:

<if test="orderAmount != null and orderAmount != ''">`order_amount` = #{orderAmount}, </if>

字段order_amount在数据库中类型是decimal,属性名orderAmount类型是BigDecimal,

BigDecimal类型=null,无法传递null给数据库,= ' '时,无法传递0给数据库

 

解决办法:<if test="orderAmount != null and orderAmount != ''">去掉,无需做判断是否空,属性名类型是BigDecimal可以如此做,与String有所区别。

 


版权声明:本文为weixin_39142315原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。