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;
}
}
Myatis中的OGNL和bind标签的结合用法的更多相关文章
- ognl,jstl,struts2标签中符号#,$,%的用法
STRUTS2标签操作Map <s:iterator value="sundayMap"> <td colspan="7" ...
- Mybatis中的ognl表达式。及myabtis where标签/if test标签/trim标签
1.mybatis默认支持使用ognl表达式来生成动态sql语句 MyBatis中可以使用OGNL的地方有两处: 动态SQL表达式中 ${param}参数中 上面这两处地方在MyBatis中处理的时候 ...
- Mybatis学习笔记16 - bind标签
1.${}拼串进行模糊查询,不安全 示例代码: 接口定义: package com.mybatis.dao; import com.mybatis.bean.Employee; import java ...
- MyBatis bind标签的用法
From<MyBatis从入门到精通> <!-- 4.5 bind用法 bind标签可以使用OGNL表达式创建一个变量并将其绑定到上下文中. 需求: concat函数连接字符串,在M ...
- MyBatis中的OGNL教程
MyBatis中的OGNL教程 有些人可能不知道MyBatis中使用了OGNL,有些人知道用到了OGNL却不知道在MyBatis中如何使用,本文就是讲如何在MyBatis中使用OGNL. 如果我们搜索 ...
- mybatis bind 标签
bind 标签可以使用 OGNL 表达式创建一个变量井将其绑定到上下文中.在前面的例子中, UserMapper.xml 有一个 selectByUser 方法,这个方法用到了 like 查询条件,部 ...
- 在strut.xml 中使用ognl
在struts.xml 中使用ognl有两种方面的需求: 1. 在action执行时从struts.xml中读取param标签中的值,然后调用标签name属性相应的set方法对action中的变量赋值 ...
- Struts中的OGNL和EL表达式笔记
Struts中的OGNL和EL表达式笔记 OGNL(Object-Graph Navigation Language),可以方便的操作对象属性的表达式语言. 1.#符号的用途 一般有三种方式: 1.1 ...
- OGNL和Struts2标签
OGNL和Struts2标签 你使用过的OGNL 页面获取并输出Action属性<s:property value="userName"/> 页面中获取request保 ...
随机推荐
- 利用csv文件批量编辑更新sql
历史表(popularity_ranking)数据中只存了用户手机号,业务需求中需要新增用户昵称字段, 这里我们用户表和popularity_ranking表在不同数据库中,有两种方法:1.编写后台服 ...
- MapReduce Combiner
Combiner编程(可选步骤,视情况而定!) combiner最基本是实现本地key的归并,combiner具有类似本地的reduce功能. 如果不用combiner,那么所有的结果都是reduce ...
- 在testrpc以太坊测试环境部署智能合约
2018年03月13日 09:20:54 思无邪-machengyu 阅读数 2683 版权声明:本文为博主原创文章,转载请务必注明出处,否则追究法律责任 https://blog.csdn.ne ...
- Qt之编译MySQL数据库驱动(MSVC)
Qt之编译MySQL数据库驱动(MSVC) (2013-12-13 20:24:46) 转载▼ 标签: qt mysql qmysql qt编译mysql qt之msvc编译mysql 分类: Qt ...
- Mysql mysqldumpslow命令详解
mysqldumpslow命令 /path/mysqldumpslow -s c -t 10 /database/mysql/slow-log 这会输出记录次数最多的10条SQL语句. 其中: -s, ...
- Jmeter-app接口
1.IOS登录接口涉及的三个接口: 2.三个接口传入的参,第三个是判断用户是否登录成功的 http://118.178.247.67:8449/service/userLogin/phoneQuick ...
- C++ 基础学习笔记
c++中的左值与右值 左值与右值这两概念是从 c 中传承而来的,在 c 中,左值指的是既能够出现在等号左边也能出现在等号右边的变量(或表达式),右值指的则是只能出现在等号右边的变量(或表达式). 清除 ...
- mac配置maven项目的方法(含导入selenium包)
1.配置了java的环境变量 文件位置: /Users/lucax/.bash_profile JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1 ...
- iptables之精髓(二)
iptables实际操作 使用-v选项后,iptables为我们展示的信息更多了,那么,这些字段都是什么意思呢?我们来总结一下 pkts:对应规则匹配到的报文的个数. bytes:对应匹配到的报文包的 ...
- react中 如何异步展示后台接口的提示消息
调用接口后,后台会返回这样的一段信息提示:{"errCode":400002,"errMsg":"字段校验异常","data&qu ...