iBatis支持集合循環, 可是如何作到雙重循環, 請見下例子java
例子描述:node
須要去三張結構相同的表中獲取信息, 須要將信息拼合去重後返回sql
入參數據類型: Map<String,Object>, regions = List<OrderRegionNum>ide
class OrderRegionNums{
String regionSchema
String regionCode
List<Integer> orderNums
}spa
注意的是在標籤中的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>ci
----------------------------------------------------------------------------------------------------------------------
it
<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>