iBtais 多重嵌套循环
iBatis支持集合循环, 但是如何做到双重循环, 请见下例子
例子描述:
需要去三张结构相同的表中获取信息, 需要将信息拼合去重后返回
入参数据类型: Map<String,Object>, regions = List<OrderRegionNum>
class OrderRegionNums{
String regionSchema
String regionCode
List<Integer> orderNums
}
注意的是在标签中的property属性中使用时:不需要加 $或者# 直接regions[].orderNums
<select id="selectOrderNumListByRegionCodeByListOrderNum" resultMap="orderNumInfo" parameterClass="java.util.HashMap">
<dynamic>
<iterate property="regions" conjunction="UNION">
select distinct(r.ID),r.ORD_NR,r.ORD_RGN_CD
from $regions[].regionSchema$.table
where
r.EXCH_SRVCR_QT > 0
and r.ORD_RGN_CD = #regions[].regionCode#
and r.ORD_NR in
<iterate property="regions[].orderNums" open="(" close=")" conjunction="," >
#regions[].orderNums[]#
</iterate>
</iterate>
</dynamic>
</select>
----------------------------------------------------------------------------------------------------------------------
<isNotEmpty prepend="and" property="marketShopAuthFlatAreaDtos">
<iterate property="marketShopAuthFlatAreaDtos" conjunction="or">
project_id in
<iterate conjunction=',' property="marketShopAuthFlatAreaDtos[].projectIds" open="(" close=")">
#marketShopAuthFlatAreaDtos[].projectIds[]#</iterate>
AND
(
1!=1
<isNotEmpty prepend="or" property="marketShopAuthFlatAreaDtos[].provinceNodes" >
shop_address_province in
<iterate conjunction=',' property="marketShopAuthFlatAreaDtos[].provinceNodes" open="(" close=")">
#marketShopAuthFlatAreaDtos[].provinceNodes[].nodeCode#</iterate> </isNotEmpty>
<isNotEmpty prepend="or" property="marketShopAuthFlatAreaDtos[].cityNodes">
shop_address_city in
<iterate conjunction=',' property="marketShopAuthFlatAreaDtos[].cityNodes" open="(" close=")">
#marketShopAuthFlatAreaDtos[].cityNodes[].nodeCode#</iterate> </isNotEmpty> <isNotEmpty prepend="or" property="marketShopAuthFlatAreaDtos[].countyNodes"> shop_address_country in
<iterate conjunction=',' property="marketShopAuthFlatAreaDtos[].countyNodes" open="(" close=")">
#marketShopAuthFlatAreaDtos[].countyNodes[].nodeCode#</iterate> </isNotEmpty>
<isNotEmpty prepend="or" property="marketShopAuthFlatAreaDtos[].townNodes"> shop_address_street in
<iterate conjunction=',' property="marketShopAuthFlatAreaDtos[].townNodes" open="(" close=")">
#marketShopAuthFlatAreaDtos[].townNodes[].nodeCode#</iterate> </isNotEmpty>
)
</iterate> </isNotEmpty>
------------------------------------------------------------------------------------------------------------
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
iBtais 多重嵌套循环的更多相关文章
- java如何跳出多重嵌套循环
Java里的break能跳出循环但是只能跳出一个,goto这个在java中也只是被当作关键是,没有任何作用 要做到跳出多重嵌套循环,可以用此方法 在循环体开头设置一个标志位,设置一个标记,然后使用带此 ...
- ThinkPHP学习 volist标签高级应用之多重嵌套循环、隔行变色(转)
Action代码: public function index(){ $prod = I("get.prod_en"); $id = I("get.id", 0 ...
- 【笔试题】在 Java 中,如何跳出当前的多重嵌套循环?
笔试题 在 Java 中,如何跳出当前的多重嵌套循环? public class Demo { public static void main(String[] args) { System.out. ...
- 如何在java中跳出当前多重嵌套循环?有几种方法?
如何在java中跳出当前多重嵌套循环?有几种方法? - 两种方法 - 1.在外层循环定义标记 ok: for(int i=0;i<100;i++){ ...
- Java中如何指定跳出多重嵌套循环
今天做项目优化涉及到一个跳出指定多重嵌套循环的问题,觉得还是记录一下那么在Java中如何跳出当前的多重嵌套循环? 方法一:可以在需要的循环语句前定义一个标号,然后在里层循环体的代码中使用带有标号的br ...
- java基础面试题:java中有没有goto? 在JAVA中如何跳出当前的多重嵌套循环?
goto是Java的保留关键字,但是从来没有直接使用到goto,goto的跳转作用在Java中受到了限制,只有在特定场合下才能使用,如while for等循环中用continue.break或结合标签 ...
- 在JAVA中怎样跳出当前的多重嵌套循环?
在JAVA中怎样跳出当前的多重嵌套循环? 这道题是考察大家对于break语句的应用.同一时候也是对你多重嵌套循环的使用进行考察.在java中,要想跳出多重循环,能够在外循环语句前面定义 ...
- Java中跳出多重嵌套循环的方法
一.使用标号 1.多重嵌套循环前定义一个标号 2.里层循环的代码中使用带有标号 break 的语句 public static void main(String[] args) { ok: for(i ...
- java跳出多重嵌套循环
public class BreaklFor { public static void main(String args[]){ OK: //设置一个标记 使用带此标记的break语句跳出多重循环体 ...
随机推荐
- Maven下Spring + SpringMvc + Hibernate4 配置实例
1. 开发环境 IDEA 2. 在pom.xml中配置引用相关的包. <properties> <junit.version>4.10</junit.version> ...
- Tensorflow图像处理以及数据读取
关于tensoflow的图像的处理,看到了一篇文章,个人觉得不错.https://blog.csdn.net/weiwei9363/article/details/79917942
- Maven插件maven-shade-plugin打包配置
转载以下两篇文章 https://www.cnblogs.com/fuxinci/p/3356087.html https://chenzhou123520.iteye.com/blog/197132 ...
- Linux-01
Linux各目录的作用 /bin/ 存放系统命令的目录,普通用户和超级用户都可以执行.不过放在/bin下的命令在单用户模式下也可以执行 /sbin/ 保存和系统环境设置相关的命令,只有超级用户可以使用 ...
- go语言变量
变量可以通过变量名访问 Go 语言变量名由字母.数字.下划线组成,其中首个字符不能为数字 声明变量的一般形式是使用 var 关键字: var identifier type 变量声明 1. 指定变量类 ...
- Mybatis之批量操作
首先批量操作的优点是:大大的提高查询的效率. 举个简单的例子:如果在程序中遍历来执行sql的话,这种情况就是有多少行数据就要执行多少条sql,这样导致的效率将是非常低. 如下可能需要40s inser ...
- Excel uploading date format
if l_wa_field-value eq 'ZFIRST_REQ_DATE'. clear lv_length. lv_length = strlen( l_wa_excel-value ). c ...
- String、StringBuilder、StringBuffer 区别
public static void testStringBuffer(){ long start System currentTimeMillis(); StringBuffer sbuf = ne ...
- 分布式事务Hmily TCC源码--学习整合
一.什么是分布式事务 分布式事务是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同的分布式系统的不同节点上, 本质上来说,分布式事务是为了保证不同数据库的数据一致性 TCC事务主 ...
- 纯css3单选框/复选框美化样式代码
纯CSS 单/复选框 美化请选择iPhone 型号 iPhone 6s iPhone 6s Plus iPhone 7 iPhone 7 Plus 选择兴趣爱好 女 绘画 摄影 骑行 原理在这 ...