• 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>
  • 相关阅读:
    相机用的 SD Card 锁Lock 烂掉了,无法正常写入
    Cannon 60D 电池卡在电池槽了,拔不出来怎么办?
    免费好用的 Apple 工具(Windows 适用)
    𠝹 (界刂) 呢個字點打?
    学校或公司转ISP -boardband (上网公司)注意事项记录
    iis站点添加.asmx的映射
    跨页面传参
    setTimeout和setInterval
    鼠标获取屏幕上的固定点位置坐标
    把完整字符串分割为字符串数组
  • 原文地址:https://www.cnblogs.com/wwjldm/p/10570253.html
Copyright © 2020-2023  润新知