ibatis (mybatis) for循环拼接语句【转】
使用 , 拼接
查询条件dto
public class queryCondition
{
private String[] stuIds;
private String name;
}
查询sqlMap
<select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
select id,name from student
<dynamic prepend="where">
<isNotNull property="stuIds" prepend="and">
<iterate property="stuIds" open="id in (" close=")" conjunction=",">
#stuIds[]#
</iterate>
</isNotNull>
<isNotNull property="name" prepend="and">
name like '%$name$%'
</isNotNull>
</dynamic>
</select>
在查询条件中有一个数组stuIds,在动态标签中进行遍历,看每一个student的id是否在该数组中。
发出的语句 select id,name from student where id in ( ? , ?) ...
使用 or 拼接
查询条件dto
public class queryCondition
{
private List<Student> lst;
private String name;
}
查询sqlMap
<select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
select id,name from student
<dynamic prepend="where">
<isNotNull property="lst" prepend="and">
<iterate property="lst" open=" (" close=")" conjunction="or">
id = #lst[].id#
</iterate>
</isNotNull>
<isNotNull property="name" prepend="and">
name like '%$name$%'
</isNotNull>
</dynamic>
</select>
发出的语句 select id,name from student where (id = ? or id = ?)...
ibatis (mybatis) for循环拼接语句【转】的更多相关文章
- ibatis Dynamic总结(ibatis使用安全的拼接语句,动态查询)
ibatis中使用安全的拼接语句,动态查询,ibatis比JDBC的优势之一,安全高效 说明文字在注释中 一.引入 一个小例子 <select id="selectAllProduc ...
- ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]>
ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]> 因为这个是xml格式的,所以不允许出现类似">"这样的字符,但是都 ...
- ibatis/mybatis显示sql语句 log4j.properties配置文件
将ibatis/mybatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运行的sql语句,方便调试: ### 设置Logger输出级别和输出目的地 ### log4j.rootL ...
- iBatis --> MyBatis
从 Clinton Begin 到 Google(从 iBatis 到 MyBatis,从 Apache Software Foundation 到 Google Code),Apache 开源代码项 ...
- 详解Java的MyBatis框架中SQL语句映射部分的编写
这篇文章主要介绍了Java的MyBatis框架中SQL语句映射部分的编写,文中分为resultMap和增删查改实现两个部分来讲解,需要的朋友可以参考下 1.resultMap SQL 映射XML 文件 ...
- iBatis & myBatis & Hibernate 要点记录
iBatis & myBatis & Hibernate 要点记录 这三个是当前常用三大持久层框架,对其各自要点简要记录,并对其异同点进行简单比较. 1. iBatis iBatis主 ...
- JDBC、ibatis(mybatis)、Hibernate有什么不同?
①JDBC编程流程固定,同时将sql语句和java代码混在了一起,经常需要拼凑sql语句,细节很繁琐: ②ibatis(mybatis)它不完全是一个ORM框架,因为MyBatis需要程序员自己编写S ...
- 关于SSM中mybatis向oracle添加语句采用序列自增的问题
在SSM向oracle数据库中插入语句时,报错如下: ### Error updating database. Cause: java.sql.SQLException: 不支持的特性 ### SQ ...
- paip.环境配置整合 ibatis mybatis proxool
paip.环境配置整合 ibatis mybatis proxool 索引: ///////////1.调用 ///////////////2. ibatis 主设置文件 com/mijie/ho ...
随机推荐
- FZU软工实践–团队成员交换交接情况
0.前言 本次交接主要是为了之后Beta冲刺工作可以更加顺利而进行的.因为我跟其他队友交互不够方便,而且我们项目当前比较缺做前端的人员,后端功能已基本实现.所以我换出来了.希望大家可以顺顺利利做完一步 ...
- HTML 5 placeHolder
<html> <body> <input type="text" id="idNum" placeholder="pla ...
- logstash 使用kafka范例
写入到kafka input { stdin { } } output { kafka { bootstrap_servers => "10.0.0.200:9092" to ...
- ansible系列7-mysql_user模块
添加mysql的用户和权限.密码 新增mysql用户zhang,设置登录密码zhang,给予权限zabbix.*:ALL ansible dba -m mysql_user -a 'login_hos ...
- BZOJ1785[USACO 2010 Jan Gold 3.Cow Telephones]——贪心
题目描述 奶牛们建立了电话网络,这个网络可看作为是一棵无根树连接n(1 n 100,000)个节点,节点编号为1 .. n.每个节点可能是(电话交换机,或者电话机).每条电话线连接两个节点.第i条电话 ...
- (转)poj算法做题顺序
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj329 ...
- 03 自学Aruba之2.4GHz及5GHz无线信道
点击返回:自学Aruba之路点击返回:自学Aruba集锦 03 自学Aruba之2.4GHz及5GHz无线信道 1. 2.4GHz信道 在各国家授权使用的频段: 信道号 中心频率(GHz) 美国FC ...
- android 图片处理经验分享
在设置ImageView资源的时候,这时的图片是来自SD卡,查看API很容易就会看到view.setImageUri(Uri u)这个函数.所以一般会这样写: ImageView view = (I ...
- 洛谷 P2746 [USACO5.3]校园网Network of Schools 解题报告
P2746 [USACO5.3]校园网Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作"接受学校&q ...
- scrapy 中间件
一.中间件的分类 scrapy的中间件理论上有三种(Schduler Middleware,Spider Middleware,Downloader Middleware),在应用上一般有以下两种 1 ...