• 案例借鉴: 
       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)

 

 

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐