1、collection:与choose when混合使用
insert into wm_out_order_${tabelName} (WMOO_ID, WMOO_CODE )
values
<foreach collection="list" item="item" index="index" separator="," >
( #{item.wmooId,jdbcType=INTEGER},#{item.wmooCode,jdbcType=VARCHAR}
)
</foreach>
3、查询条件: 其中如果collection size不能过大,会导致foreach查询失败
<select id="listExcel" parameterType="com.wlyd.fmcgwms.util.CondOrderLimit" resultMap="BaseResultMap">
select * from wm_out_order_${tabelName}
where 1=1
<if test="conditions.wmooCodes != null and conditions.wmooCodes != ''" >
and o.WMOO_CODE in
<foreach collection="conditions.wmooCodes" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
多个条件:
<select id="trackForBatchExport" resultMap="BaseResultMap" parameterType="com.wlyd.fmcgwms.util.CondOrderLimit">
select DISTINCT o.*,op.WMOP_BATCHPICK_NO wmooBatchpickNo,ca.EB_CARRIER_NAME wmooCarrierName,c.CDST_CUSTOMER_CODE wmooCustomerCode
from wm_out_order_${conditions.companyCode} o
LEFT JOIN wm_batch_picking_${conditions.companyCode} bp on o.WMOO_BAT_PIC_ID=bp.WMBP_ID
left join eb_carrier_${conditions.companyCode} ca on ca.EB_CARRIER_CODE = o.WMOO_ACTUALLY_CARRIER_CODE
left join cd_customer_${conditions.companyCode} c on c.CDST_CUSTOMER_NAME = o.WMOO_CUSTOMER_NAME
LEFT JOIN wm_out_packlist_${conditions.companyCode} op on op.WMOP_OUTORDER_CODE = o.WMOO_CODE
where 1=1
and(
<foreach collection="conditions.wmOutOrdersSearch" index="index" item="item" open="(" separator="or" close=")">
(
(o.WMOO_CODE = #{item.wmooCode} and op.WMOP_BATCHPICK_NO = #{item.wmooBatchpickNo} and op.WMOP_BATCHPICK_NO !='')
or
(o.WMOO_CODE = #{item.wmooCode} and (#{item.wmooBatchpickNo} is null or #{item.wmooBatchpickNo}=''))
)
</foreach>
)
</select>