mybatis动态sql中的trim标签的使用(转)
trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码:
1、
select * from user
<trim prefix="WHERE" prefixoverride="AND |OR">
<if test="name != null and name.length()>0"> AND name=#{name}</if>
<if test="gender != null and gender.length()>0"> AND gender=#{gender}</if>
</trim>
假如说name和gender的值都不为null的话打印的SQL为:select * from user where name = 'xx' and gender = 'xx'
在红色标记的地方是不存在第一个and的,上面两个属性的意思如下:
prefix:前缀
prefixoverride:去掉第一个and或者是or
2、
update user
<trim prefix="set" suffixoverride="," suffix=" where id = #{id} ">
<if test="name != null and name.length()>0"> name=#{name} , </if>
<if test="gender != null and gender.length()>0"> AND gender=#{gender} , </if>
</trim>
假如说name和gender的值都不为null的话打印的SQL为:update user set name='xx' , gender='xx' where id='x'
在红色标记的地方不存在逗号,而且自动加了一个set前缀和where后缀,上面三个属性的意义如下,其中prefix意义如上:
suffixoverride:去掉最后一个逗号(也可以是其他的标记,就像是上面前缀中的and一样)
suffix:后缀
mybatis动态sql中的trim标签的使用(转)的更多相关文章
- mybatis动态sql中的trim标签的使用
trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码: 1. select * from user <trim prefix="WHERE" p ...
- mybatis动态SQL中的set标签的使用
set标记是mybatis提供的一个智能标记,我一般将其用在修改的sql中,例如以下情况: <update> update user <set> <if test=&qu ...
- MyBatis动态SQL中trim标签的使用
My Batis 官方文档 对 动态SQL中使用trim标签的场景及效果介绍比较少. 事实上trim标签有点类似于replace效果. trim 属性 prefix:前缀覆盖并增加其内容 suffix ...
- MyBatis动态SQL之一使用 if 标签和 choose标签
bootstrap react https://segmentfault.com/a/1190000010383464 xml 中 < 转义 to thi tha <if test=&qu ...
- mybatis动态sql中的两个内置参数(_parameter和_databaseId)
mybatis动态sql中的两个内置参数(_parameter和_databaseId) <!-- mybatis动态sql的两个内置参数 不只是方法传递过来的参数可以被 ...
- mybatis动态sql中where标签的使用
where标记的作用类似于动态sql中的set标记,他的作用主要是用来简化sql语句中where条件判断的书写的,如下所示: <select id="selectByParams&qu ...
- Mybatis动态SQL——if,where,trim,choose,set.foreach的用法
知识点:主要介绍mybatis中,动态sql中的if,where,trim,set,foreach的用法 自学谷粒学院mybatis学习视频,参考mybatis官方文档 java包:log4j.jar ...
- mybatis动态sql中foreach标签的使用
foreach标签主要用于构建in条件,他可以在sql中对集合进行迭代.如下: <delete id="deleteBatch"> delete from user w ...
- mybatis动态sql中的sql标签——抽取可重用的sql片段
1.用<sql>标签抽取可重用的sql片段 <!-- 抽取可重用的SQL片段,方便后面引用 1.sql抽取,经常将要查询的列名,或者插入用的列名,之后方便引用 ...
随机推荐
- document.write('<script type=\"text/javascript\"><\/script>')
document.write('<script type=\"text/javascript\"><\/script>')
- 菜鸟-手把手教你把Acegi应用到实际项目中(10)-保护业务方法
前面已经讲过关于保护Web资源的方式,其中包括直接在XML文件中配置和自定义实现FilterInvocationDefinitionSource接口两种方式.在实际企业应用中,保护Web资源显得非常重 ...
- 使用Donut Caching和Donut Hole Caching在ASP.NET MVC应用中缓存页面
Donut Caching是缓存除了部分内容以外的整个页面的最好的方式,在它出现之前,我们使用"输出缓存"来缓存整个页面. 何时使用Donut Caching 假设你有一个应用程序 ...
- SICP 1.1-1.5
1.1 a = b = nil 1.2 (/ (+ (- (- (+ (/ ))))) (* (- ) (- )) 1.3 a = b = nil 1.4... 1.5 (define (p) (p) ...
- Linux-wget/tar/ln 函数
1. 获取软件包,可以使用wget的方式, ubuntu可以使用apt-get source来获取源代码 wget 是一个在网络上进行下载的简单而强大的自由软件,支持HTTP,HTTPS,FTP协议, ...
- Testing and Checking Refined
还是James大叔的文章:http://www.satisfice.com/blog/archives/856 本文提出了Testing和checking的定义和他们之间的区别. ========== ...
- ASP.NET Razor 视图引擎编程参考
ASP.NET Razor 视图引擎编程参考 转载请注明出处:http://surfsky.cnblogs.com Rasor 视图引擎 http://msdn.microsoft.com/ ...
- hadoop,hbase,pig安装
注意端口,办公网只能访问8000-9000的端口 pig的一些lib文件版本 /home/map/hadoop/lib下一些98.5的lib没删除
- Secure your iPhone with 6 digit passcode by upgrading to iOS9
IP-Box could crack 4 digit passcode, what about 6 digit passcode??? All you need to do is to upgrade ...
- javaSE第九天
第九天 50 1. final关键字(掌握) 50 (1)定义: 50 (2)特点: 51 (3)面试相关: 51 A:final修饰的局部变量 51 B:fi ...