天天看点

Mybatis if test in的用法前言使用方法

前言

mapper中用到一些OGNL,其中in的用法这里说一下

使用方法

<if test="status!=null and status in {100,1000,2000}">
           

官网文档的说法:

To create a list of objects, enclose a list of expressions in curly braces. As with method arguments, these expressions cannot use the comma operator unless it is enclosed in parentheses. Here is an example:

name in { null,"Untitled" }
           

This tests whether the name property is null or equal to "Untitled".

The syntax described above will create a instanceof the List interface. The exact subclass is not defined.

e1 in e2
List membership comparison
           

Mybatis中常用的OGNL表达式有以下:

e1 or e2
e1 and e2
e1 == e2,e1 eq e2
e1 != e2,e1 neq e2
e1 lt e2:小于
e1 lte e2:小于等于,其他gt(大于),gte(大于等于)
e1 in e2
e1 not in e2
e1 + e2,e1 * e2,e1/e2,e1 - e2,e1%e2
!e,not e:非,求反
e.method(args)调用对象方法
e.property对象属性值
e1[ e2 ]按索引取值,List,数组和Map
@[email protected](args)调用类的静态方法
@[email protected]调用类的静态字段值
           
更加详细的介绍可以参考官网的介绍:https://commons.apache.org/proper/commons-ognl/language-guide.html 

继续阅读