MyBatis支持的OGNL语法
Mybatis支持OGNL的语法
OgnlCache
用于解析静态方法
org.apache.ibatis.scripting.xmltags.TextSqlNode.BindingTokenParser#handleToken
org.apache.ibatis.scripting.xmltags.OgnlCache#getValue
org.apache.ibatis.scripting.xmltags.OgnlCache#parseExpression解析表达式
org.apache.ibatis.ognl.Ognl#parseExpression
org.apache.ibatis.ognl.OgnlParser#staticReference
org.apache.ibatis.ognl.OgnlParser#staticMethodCall
org.apache.ibatis.ognl.OgnlRuntime#callStaticMethod
在sql映射语句中可以支持引入以下几种方式
示例SQL
<select id="getUserById" resultMap="BaseResultMap">
select * from user
<if test="id != null">
<where>
name = #{name}
and id =${id}
and id = ${user.id}
and id = ${@@abs(-12345678)}
and id = ${@Integer@parseInt("654")}
and id='${@cn.followtry.mybatis.bean.User@name()}'
and id='${@org.apache.commons.lang3.math.NumberUtils@isNumber("sdfghjk")}'
and id='${new cn.followtry.mybatis.bean.User()}'
and id=${@cn.followtry.mybatis.bean.User@haha}
and id='${@cn.followtry.mybatis.bean.User@arr[1]}'
and id='${@cn.followtry.mybatis.bean.User@list[1]}'
and id='${@[email protected]("123")}'
and id='${@[email protected]()}'
</where>
</if>
limit 100
</select>- 变量
id =${id} - 属性
id = ${user.id} - 静态方法(public)- 无参数
id='${@cn.followtry.mybatis.bean.User@name()}' - 待参数
id='${@org.apache.commons.lang3.math.NumberUtils@isNumber("abcd")}' - 静态属性(public)
id=${@cn.followtry.mybatis.bean.User@aaa} - 数组索引
id='${@cn.followtry.mybatis.bean.User@arr[1]}' - 集合
'${@cn.followtry.mybatis.bean.User@list[1]}' - Map
id='${@[email protected]("123")}'id='${@cn.followtry.mybatis.bean.User@map}' - Enum
id=${@[email protected]()} - 构造方法
id='${new cn.followtry.mybatis.bean.User()}' - java.lang.Math的静态方法
id = ${@@abs(-12345678)}可以省略class的编写,方法的默认class是java.lang.Math - java.lang包下的静态方法
id = ${@Integer@parseInt("654")}可以省略package的编写,类默认的package是java.lang
${}语法中通过两个@字符,前者定位到Java类,后者定位到类中的方法或属性
这里只列出的其中一部分,对于Mybatis支持的${}语法,可以参见OGNL语法手册。
相关推荐
MrLiar 2020-07-07
xiuyangsong 2020-11-16
Nishinoshou 2020-11-09
jimgreatly 2020-09-01
dongxurr 2020-08-18
Dullonjiang 2020-08-15
Dullonjiang 2020-08-11
Dullonjiang 2020-08-09
dongxurr 2020-08-08
yunzhonmghe 2020-08-07
jimgreatly 2020-08-03
Dullonjiang 2020-07-30
jimgreatly 2020-07-27
liqiancao 2020-07-26
xiuyangsong 2020-07-26
dongxurr 2020-07-26
mcvsyy 2020-07-26
helloxusir 2020-07-25