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

来源:互联网 发布:php 数组头部添加元素 编辑:程序博客网 时间:2024/06/05 06:11

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>
原创粉丝点击