mybatis传参、被逗号、分割的字符串、数组传参

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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐 城

小朋友,你是不是有很多问号?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值