Mybatis查询SQL中如何使用in?

这里整理一个只传一个参数的demo,该参数为字符串数组。

这里foreach动态语句,

foreach的参数:

foreach元素的属性主要有 item,index,collection,open,separator,close。

item表示集合中每一个元素进行迭代时的别名.

index指 定一个名字,用于表示在迭代过程中,每次迭代到的位置.

collection中放传过来的参数。

open表示该语句以什么开始,separator表示在每次进行迭代之间以什么符号作为分隔 符.

close表示以什么结束。

xml 如下

<select id="getList" resultType="Student">

        select * from student a 

       where a.del_flag='0' and a.name in

        <foreach item="item" index="index" collection="nameArray"  open="(" separator="," close=")">
                #{item}
        </foreach>

 </select>

对应的Java接口如下:

List<DataStandard> getListByFileName(@Param(value="nameArray") String[] nameArray);   


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值