1. 程式人生 > >mybaitis 的 mapper.xml 檔案中 引數為List集合SQL 的寫法。

mybaitis 的 mapper.xml 檔案中 引數為List集合SQL 的寫法。

1、應用場景:
傳參:
MaterialCodeList, activity_end_time,userCode
具體SQl:
 <if test> 的驗證: "MaterialCodeList != null and MaterialCodeList.size()>0"
<foreach > 迴圈: 迴圈體:item  序號:index 集合:collection  分割符:separator

 
 
 
<select id="selectPreDiscountInfoByErpCodeAndMaterialCode"  resultMap
="BaseResultMap"> SELECT ps.MATERIAL_CODE,ps.`NAME`,ps.DISCOUNT_AMOUNT from pre_discount_sku ps where ps.pre_discount_id in( select pd.id from pre_discount pd where pd.discount_status = '1' and pd.user_code = #{userCode,jdbcType=VARCHAR} and to_days(pd.activity_end_time) >= to_days(now()) ) <
if test="MaterialCodeList != null and MaterialCodeList.size()>0"> and ps.material_code in( <foreach item="item" index="index" collection="MaterialCodeList" separator=","> #{item} </foreach> ) </if> </select>