mybatis的 條件判斷

在使用 MyBatis if 進行條件判斷時,一直報錯:

<if test="fwbdh != null and fwbdh == 'BAK'">  
    fwbdh=#{fwbdh}  
<if>  

MyBatis是使用的OGNL表達式來進行解析的,改成:

<if test='fwbdh != null and fwbdh == "BAK"'>  
    fwbdh=#{fwbdh}  
<if>  

同時,MyBatis的if、when裏面的test表達式對參數進行判斷時,可以調用java的java.lang.String中定義的方法:
比如:

<if test="fwbdh != null and fwbdh != ''">  
    <choose>    
        <when test='fwbdh.indexOf(",") != -1'>    
            AND t.FWBDH  in (${fwbdh})   
        </when>    
        <otherwise>     
                AND t.FWBDH like '%'+#{fwbdh}+'%'    
        </otherwise>    
    </choose>   
</if>  

轉:http://blog.csdn.net/xxlian1201/article/details/52759349

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章