案例借鉴:
SELECT * FROM yp_popup_store_info store WHERE store.store_id IN <foreach item="item" index="index" collection="ids.split(',')" open="(" separator="," close=")"> '${item}' </foreach>
实际使用:
parameterType="pd"(是我封装的类似于map的参数集)
<select id="countAttendByDate" parameterType="pd" resultType="Integer"> select count(distinct c.user_id) as count from dd_b_pc_attendance_clock c WHERE 1=1 <if test="deptId !=null and deptId !=''"> AND c.dept_id <foreach collection="deptId.split(',')" item="deptId" index="index" open="in(" close=")" separator=","> #{deptId} </foreach> </if> <if test="beginTime != null and endTime != null and beginTime != '' and endTime != ''"> AND c.user_check_time BETWEEN #{beginTime} AND #{endTime} </if> </select>
其他
<select id="countsByUserId" parameterType="Integer[]" resultType="java.lang.Integer" > SELECT count(DISTINCT userid,mobile,name,unionid) FROM s_sys_user <where> dept_id <foreach collection="array" item="deptId" open="in(" close=")" separator=","> #{deptId} </foreach> AND name NOT IN ("天干物燥") </where> </select>
下面这个未测试 ,是别人写的(NOT IN)