1.单个参数
public List<Article> getInIds(List<String> ids);
<select id="getInIds" resultType="com.testmybatis.model.Article">
select * from article
where
type = 1
<if test="list !=null and list.size>0">
and id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
2.多个参数
public List<Article> getInIdsAndType(@Param("type")int type,@Param("list")List<String> ids);
<select id="getInIdsAndType" resultType="com.testmybatis.model.Article">
select * from article
where
type = #{type}
<if test="list !=null and list.size>0">
and id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>