mybatis之动态sql foreach

应项目需求需要,有的时候动态sql中一个字段需传入多个参数组成的数组,下面是具体实现

@RequestParam(value = "cardmerchantId", required = false) String merchantId) throws Exception{//景点--区分景点标识
String[] idMerchants = merchantId.split(",");//mybatis也可以接收和处理list类型的参数,在sql语句中的处理方式和数组的处理方式是一样的
param.put("id_merchant",idMerchants);

sql语句:

<if test="id_merchant!=null and id_merchant !=''">
     AND cmii.id_merchant in
     <foreach collection="id_merchant" item="value" open="(" close=")" separator="," index="index">
        #{value}
    </foreach>
</if> 

 

posted @ 2017-07-24 09:22  十月围城小童鞋  阅读(97)  评论(0编辑  收藏  举报