Nishinoshou 2019-06-25
用于解析静态方法
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}id='${@cn.followtry.mybatis.bean.User@name()}'id='${@org.apache.commons.lang3.math.NumberUtils@isNumber("abcd")}'id=${@cn.followtry.mybatis.bean.User@aaa}id='${@cn.followtry.mybatis.bean.User@arr[1]}''${@cn.followtry.mybatis.bean.User@list[1]}'id='${@[email protected]("123")}'id='${@cn.followtry.mybatis.bean.User@map}'id=${@[email protected]()}
id='${new cn.followtry.mybatis.bean.User()}'id = ${@@abs(-12345678)} 可以省略class的编写,方法的默认class是java.lang.Mathid = ${@Integer@parseInt("654")} 可以省略package的编写,类默认的package是java.lang${}语法中通过两个@字符,前者定位到Java类,后者定位到类中的方法或属性
这里只列出的其中一部分,对于Mybatis支持的${}语法,可以参见OGNL语法手册。