mybatis查询配置文件中关于 in 的条件查询

1.dao层 条件参数Map中传入String[] 字符串数组

HashMap<String,Object> paramsMap=new HashMap<String,Object>();
String[] strArr={"1","2"};
paramsMap.put("deptIds",strArr );
List list=dao.findList(paramsMap);

2.dao对应的sql.xml中 in 查询写法如下:

<select id="findList" resultType="HashMap" parameterType="HashMap">
select dept_id,dept_name from table A
<where>
<if test="deptIds != null and deptIds!=''">
    AND A.DEPT_ID IN
    <foreach item="item" index="index" collection="deptIds"   open="(" separator="," close=")">  
              #{item}   
    foreach>  
if>
where>
select>

你可能感兴趣的:(mybatis查询配置文件中关于 in 的条件查询)