1. 程式人生 > >mybatis當傳入資料型別為Int時並且值為0時,會判斷為空字串

mybatis當傳入資料型別為Int時並且值為0時,會判斷為空字串

一般在mybatis中插入或者修改時,會將欄位做非null和非空判斷,如下所示:

<if test="operatype_enum != null and operatype_enum != ''">

operatype_enum =#{operatype_enum},

</if>

這樣寫,當operatype_enum=0時,mybatis將不會插入改欄位,因為mybatis框架會將operatype_enum識別為空字串,

所以如果想要將0值插入進去,有一下幾種方法解決:

1.直接改框架原始碼

2.更改if判斷條件如下所示

<if test="operatype_enum != null">

operatype_enum =#{operatype_enum},

</if>

<if test="operatype_enum != null and operatype_enum != '' or operatype_enum == 0">

operatype_enum =#{operatype_enum},

</if>