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保 ...
随机推荐
- 通过蓝牙共享网络设置Charles抓包
在办公室连接WiFi时,电脑和移动设备分配到的IP地址不在同一网段, 但是Android系统提供了一个非常方便的功能,可以搭建一个网络使得这两台设备处于同一网段,实现无障碍访问,使用Charles抓包 ...
- win10+mysql8.0安装
一.下载 mysql8.0 windows zip包下载地址: https://dev.mysql.com/downloads/mysql/ 1540951981(1).png 二.安装 1.解压 ...
- Windows使用Vagrant&VirtualBox搭建虚拟开发环境
Vagrant 是一款用来构建虚拟开发环境的工具 , 我们可以通过 Vagrant 封装一个 Linux 的开发环境 , 分发给团队成员 ; 成员可以在自己喜欢的桌面系统 Mac/Windows/Li ...
- ILI9341液晶显示
17.1液晶显示原理 TFT-LCD(Thin Film Transistor Liquid Crystal Display)即薄膜晶体管液晶显示器,是微电子技术与液晶显示器技术巧妙结合的的一种技术. ...
- 重学C语言
重学C语言 #include <stdio.h> int main() { ; ; printf("I am %d year old.\n",age); printf( ...
- 一百三十五:CMS系统之UEditoe编辑器集成以及配置将图片上传到七牛
富文本编辑框,选择UEditor 下载地址:http://ueditor.baidu.com/website/download.html 使用说明:http://fex.baidu.com/uedit ...
- 假如React没了JSX
如题,想必React大家早已不陌生,而React里面的JSX都是玩的得心应手了,但是假如说React里面没有了React那会是一种什么样的情形呢,我们来简单的看一下. 首先我们来实现一个简单的list ...
- [C++]Yellow Cards - GYM - 102348A(Practice *) - CodeForces
1 Problem Description Problem The final match of the Berland Football Cup has been held recently. Th ...
- Ubuntu 18.04 下 PostgreSQL 10 的安装与基础配置
下载安装 在命令行执行如下语句: apt-get install postgresql-10 该指令会帮助你下载如下PostgreSQL组件: name |explain | ------------ ...
- iOS-iOS 支付 [支付宝、银联、微信](转)
支付宝iOSsdk官方下载sdk地址:https://b.alipay.com/order/productDetail.htm?productId=2013080604609654&tabId ...