WenJieWangFlyToWorld

导航

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>

posted on 2019-03-21 11:09  WenjieWangFlyToWorld  阅读(256)  评论(0编辑  收藏  举报