1.非xml方式,使用注解传in,要使用

@Select("<script>" +
            "SELECT count(DISTINCT member_id) as memberCount\n" +
            "from member_analysis\n" +
            "WHERE agent_id in <foreach item='item' index='index' collection='memberIds' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
Integer getCountWithAgentId(@Param("memberIds") List<String> memberIds);

其中的foreach的collection直接写成@param中的值即可。

2.在入参前进行字符串封装,拼成(,,,,)传值

@Select("SELECT count(DISTINCT member_id) as memberCount from member_analysis where access_pat_id in (#{memberIds})")
    Integer getCountWithAgentId(@Param("memberIds")String memberIds);

使用方法返回

 public static String indexForm(List<String> s){
        String content="";
        int i=0;
        for (String ss:s){
            i++;
            if (i==s.size()){
                content+=ss;
            }else {
                content+=ss+",";
            }
        }
        return content;
    }

或者使用

StringUtils.join(memberIds.toArray(),",")

3.正常流程的xml方法

    <select id="findByIds" resultMap="BaseResultMap">
        select * from dictionaries
        <where>
            dictionaries.key  in 
            <foreach  item="item" index="index" collection="memberTypes" open="(" separator="," close=" )">
                 #{item}
        	</foreach>
        </where>
    </select>
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐