Mybatis 传入一个数组,判断某个字段在数组里

Mapper:

List<xxx> getAll(@Param("platformArray") String[] platformArray);

Sql:

select * from xx where
<if test="platformArray != null and platformArray.length > 0">
    Platform IN
    <foreach collection="platformArray" index="index" item="item"
             open="(" separator="," close=")">
        #{item}
    </foreach>
</if>

实际拼出来的sql:

select * from xx where Platform IN ("a","b")

版权声明:本文为zhanghe_zht原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。