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>
划船不用桨、杨帆不等风、一生全靠浪

浙公网安备 33010602011771号