• Myatis中的OGNL和bind标签的结合用法


    1.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
    @class@method(args)调用类的静态方法
    @class@field调用类的静态字段值

    2.模糊查询标签<bind>

    <select id="getUser" resultType="User">
    <bind name="name" value="'_'+ob+'%'"/>
    select *
    from user
    where name like #{name}
    </select>

    3.<bind>标签的特殊使用

    (代码中bind标签的value值@com.syg.gamemanage.util.MbValid@instance()
    采用OGNL表达式@class@method(args)调用类的静态方法这里的目的是采用单例模式(懒汉模式)创建对象)
    MbValid.noZero(example.id)调用对象的方法返回值为boolean类型

    <select id="queryList"   resultType="Operation">
    select * from operation
    <where>
        <bind name="MbValid" value="@com.syg.gamemanage.util.MbValid@instance()"/>
        <if test="MbValid.noZero(example.id)">and id = #{example.id}</if>
        <if test="MbValid.str(example.operationName)">and operation_name = #{example.operationName}</if>
        </where>
        order by create_ts 
      </select>
        public class MbValid {
            private static MbValid instance;
            //懒汉模式
        public static MbValid instance() {
            if (instance == null) {
                instance = new MbValid();
            }
            return instance;
        }
    
        public static boolean str(String str) {
            if (str == null || str.trim().length() <= 0) {
                return false;
            }
            return true;
        }
    
    
        public static boolean noZero(Integer integer) {
            if (integer == null || integer == 0) {
                return false;
            }
            return true;
        }
        
    }
  • 相关阅读:
    选择器 nth-child和 nth-of-type的区别
    Numpy基础数据结构 python
    猜数字问题 python
    猴子吃桃问题 python
    random模块 time模块的用法 python
    统计输入任意的字符中中英文字母,空格和其他字符的个数 python
    匿名函数lambda python
    函数的可变参数问题
    两组列表组合成一个字典,一一对应
    遍历字典的几种方式
  • 原文地址:https://www.cnblogs.com/wgj-master/p/7891289.html
Copyright © 2020-2023  润新知