????foreach標(biāo)簽?zāi)軌驅(qū)魅氲膌ist、array進(jìn)行迭代
????在對(duì)同一字段缎脾,使用多個(gè)不同的查詢參數(shù)查詢泼诱,使用這個(gè)標(biāo)簽有很好的效果。今天記錄一下使用foreach分別對(duì)不同字段like和in的簡(jiǎn)單查詢赊锚。
直接放Mapping
<select id="getChanceAnalysePC" parameterType="java.util.HashMap" resultType="java.util.HashMap">
with temp as?(?select *?from?(select t.*?,row_number() over(partition by? t.s_info_compname order by t.create_date desc) as rn?from rpt_chance_analyse_datas t?where t.create_date >sysdate -7)?where rn=1)
select *?from temp?where 1=1
<if test="companyName !=null and companyName !='' ">
????????????AND S_INFO_COMPNAME LIKE '%' || #{companyName} || '%'? ? ? ?
</if>
<!--like部分,collection代表你的list屉栓、array在Map中的key舷蒲;separator會(huì)在每次迭代加OR,注意AND和()的位置-->
<if test="productList !=null ">
AND
(?
????<foreach collection="productList" index="index" item="product" separator="OR" >
????????????sort_flag like '%'||#{product}||'%'
? ? </foreach>? ? ? ? ? ?
)
</if>
<!--in部分友多,注意這個(gè)separator要用英文逗號(hào)牲平,如果需要自己組裝list,組裝之前也別用中文逗號(hào)做分隔符域滥,剛踩完-->
<if test="plateList !=null ">
????????AND boardname in
????????<foreach collection="plateList" index="index" item="plate" open="(" separator="," close=")" >
? ? ? ? ? ? ? ? #{plate}?
? ? ? ? </foreach>? ? ? ? ? ?
</if>
</select>