使用@Select注解时使用in传入ids数组作为参数

最近用到Mybatis的注解sql方式,结果发现在传入多个id作为参数跟xml的用法不太一样,到网上搜罗了一些方法,很多都会报错,最后如下方法调通了,重点是script标签,和参数的名字:

@Select({
            "<script>",
            "select",
            "c.cust_id, plat_cust_id, plat_cust_name, cust_map_id, cust_type, is_merchant, ",
            "create_time, create_opt_id, p.cust_name, p.tel, p.id_type, p.id_no ",
            "from personal_customer p",
            "left join customer c",
            "on c.cust_id = p.cust_id",
            "where p.cust_id in ",
                "<foreach item='item' index='index' collection='ids'",
                "open='(' separator=',' close=')'>",
                "#{item}",
                "</foreach>",
            "</script>"
    })
    @ResultMap("com.cloud.customer.dao.PersonalCustomerMapper.PersonDOResultMap")
    List<PersonInfoDO> selectRecordsByIds(@Param("ids") String[] ids);
}

在sql语句两头用script标签包起来,然后中间用foreach正常编辑,参数注入一个String数组,就可以完成查询了

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值