zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Spring 框架的概述以及Spring中基于XML的IOC配置
    SpringBoot(1)
    C/C++经典程序之打印三角形
    C++构造函数详解(复制构造函数)
    利用函数模板计算并返回数组d 中size个元素的平方和
    C++模板之typename和class关键字的区别
    构造函数与成员函数的区别?
    为什么多数穷人很难逆袭成功
    用递归方式求解这个问题:一只母兔从四岁开始每年生一只小母兔,按此规律,第n年有多少只母兔?
    编写一个函数 reverseDigit(int num).该函数读入一个整数,然后将这个整数的每个位上的数字逆序输出。
  • 原文地址:https://www.cnblogs.com/wwjldm/p/10570253.html
Copyright © 2011-2022 走看看