1. 程式人生 > >mybatis的一個bug,將整數0識別為null,導致sql執行失敗

mybatis的一個bug,將整數0識別為null,導致sql執行失敗

本文內容整理來源:http://blog.csdn.net/john1337/article/details/70230563


今天在使用mybatis時遇到一個問題,Java程式碼中傳遞的整數0在mybatis中被識別成null

[html]  view plain  copy
  1. <where>  
  2.     <if 
    test="status != null and status !=''">  
  3.         and status=#{status,jdbcType=INTEGER}  
  4.     </if>  
  5. </where>  


如果java程式碼需要往mybatis傳遞整數0,那麼需要使用增強版的判斷,具體如下所示:

[html]  view plain  copy
  1. <where>  
  2.     <if test="status != null and status !='' or status==0">  
  3.         and status
    =#{status,jdbcType=INTEGER}  
  4.     </if>  
  5. </where>