<if test="valiStatus==null || valiStatus=='' || valiStatus==4 "> b.work_permit_card_cert is not null and b.work_permit_card_cert!=1 and b.delete_flag =0 </if> <if test="valiStatus==0"> u.user_type = 0 and b.work_permit_card_cert = 0 and b.delete_flag =0 </if> <if test="valiStatus==2"> u.user_type=1 and b.work_permit_card_cert=2 and b.delete_flag =0 </if>
其中viliStauts 是一個 Integer 型的參數 , 如果 傳入 4 和2 是可以正確的執行 if 條件的 。。
但是如果傳入0 的話 , 就會出現 前兩個 if 條件都判斷正確的情況,導致sql 錯誤。
解決辦法是不要寫valiStatus=='' 的判斷,(以后要注意類型問題,Integer 就不要判斷 ==''了)
其他知識點: like concat('%'+#{a} + '%');
並且 : 使用 and