1. 程式人生 > >mybatis引數String與Integer型別的判斷

mybatis引數String與Integer型別的判斷

mybatisupdate時,正常是set了值才會進行update操作,我們一般是這樣寫:

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

SAMPLE_BATCH_NO =#{sampleBatchNo,jdbcType=VARCHAR},

</if>

1 String型別是符合的,但是如果是Integer型別的話,mybatis會將i==0的值也認定為空字串。

所以如果是Integer型別只需要判斷!= null即可

2如果String型別需要判斷不等於0,則需要寫sampleBatchNo != '0'.toString(),否則會報錯。