mybaitis 的 mapper.xml 文件中 参数为List集合SQL 的写法。

mybaitis 的 mapper.xml 文件中 参数为List集合SQL 的写法。
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

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>

 

本文来源凌枫zero,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/7991

发表评论