在Mybatis的动态SQL和${}形式的参数中都用到了OGNL表达式。Mybatis常用的OGNL表达式如下
1、e1 or e2:或
<if test="userEmail != null or userEmail == '1'">
</if>
1
2
2、e1 and e2:且
<if test="userEmail != null and userEmail != ''">
</if>
1
2
3、e1 == e2 或e1 eq e2:相等
<if test="userEmail == null and userEmail == ''">
</if>
1
2
4、e1 != e2 或 e1 neq e2:不等
<if test="userEmail != null and userEmail != ''">
</if>
1
2
5、e1 lt e2:小于
<if test="age lt 10">
#{userEmail,jdbcType=VARCHAR},
</if>
1
2
3
6、e1 lte e2:小于等于
7、e1 gt e2:大于
8、e1 gte e2:大于等于
9、 e1 + e2(加),e1 - e2(减),e1 * e2(乘),e1/e2(除),e1%e2(余)
10、!e或not e:非,取反
11、e.method(args):调用对象方法
<if test="list != null and list.size() > 0 ">
#{userEmail,jdbcType=VARCHAR},
</if>
1
2
3
12、e.property:对象属性值
<select id="selectByUserIdAndEnabledUseBean" resultMap="BaseResultMap">
select r.id, r.role_name, r.enabled, r.create_by, r.create_time,
u.user_name as "user.userName", u.user_email as "user.userEmail"
from sys_user u
inner join sys_user_role ur on u.id = ur.user_id
inner join sys_role r on ur.role_id = r.id
where u.id = #{user.id} and r.enabled = #{role.enabled}
</select>
1
2
3
4
5
6
7
8
9
13、e1[e2]:按索引取值(List、数组和map)
14、@class@method(args):调用类的静态方法
<bind name="name" value="@ex.mybatis.rbac.mapper.UserMaperTest@setName()"/>
1
15、@class@field:调用类的静态字段值
<bind name="name" value="@ex.mybatis.rbac.mapper.UserMaperTest@NAME"/>
作者:Moss Huang
来源:CSDN
原文:https://blog.csdn.net/q283614346/article/details/83119073
版权声明:本文为博主原创文章,转载请附上博文链接!
网友评论