mybatis 傳參為 Integer 時 ,Mapper 文件 中判斷 條件 問題。


<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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM