最近遇到一些 問題 就是mybatis中是否可用 使用 el的表達式,我原先同事很是否定 el表達式,但是 我在想 標籤下可用使用的,爲什麼到mybatis中就不可以使用,難道 用了兩套的規則,然後我就去 試驗一波,後來發現 並不是不可以用 其實就是我們很少使用 el表達式 在 mybatis中,本能的反應不可能可用,但是 事實結果 是可用的。好了 下面總結一下 ,el表達式在在 mybatis的中的使用,應爲mybatis 最終全部轉化爲 ognl。
1. mybatis中 對於字符串 相等的判斷對於的操作符
<if test="username != null and 'hello' eq username"></if>
<if test="username != null and 'hello' == username"></if>
<if test="username != null and '' != username"></if>
<if test="username != null and '' neq username"></if>
eq | 對應 | == |
neq | 對應 | != |
其實這兩個沒什麼差別。
2. 對應參數判斷大小之類的
<if test='id != null and id > x'></if>
<if test='id != null and id gt x'></if>
gt | 對應 | > |
gte | 對應 | >= |
lt | 對應 | < (在條件判斷的時候,test不能包含 '<' 字符) |
lte | 對應 | <= (在條件判斷的時候,test不能包含 '<' 字符) |
3. 特定字符有問題,某業務需要
4. 判斷list 是否爲空
<if test="list != null and list.isEmpty()"></if> ,
<if test="list != null and list.size()>0"></if>
大體就是這樣