mybatis中匹配一个集合中的数据查询,且关系是or或。

           <if test="peopleType != null and peopleType == 1">
                <if test="userIds != null">
                    and (
                    <foreach collection="userIds" item="entity" separator="or">
                         b.PUBLIC_PEOPLE = #{entity}
                    </foreach>
                    )
                </if>
            </if>

完整

<select id="examQuery" resultMap="GhaExExamQueryDTOMap">
        select
        a.ID_ as groupID, a.GROUP_NAME as groupName, b.ID_,b.ISDELETED,b.TENANTID,b.OPTIME,b.OPER,b.CANCEL_TIME,
        b.UPDATETIME,b.UPDATOR,b.GROUP_ID,b.EXAM_NAME,b.EXPLAINS,b.PUBLIC_PEOPLE,b.PUBLIC_TIME,b.EXAM_STATUS,b.RECYCLE_IS,
        (select count(1) from gha_ex_my_exam where EXAM_ID = b.ID_) as answerNumber,
        c.ID_ as c_ID_,c.ISDELETED as c_ISDELETED,c.TENANTID as c_TENANTID,c.OPTIME as c_OPTIME,c.OPER as c_OPER, c.UPDATETIME as c_UPDATETIME,c.UPDATOR as c_UPDATOR,c.TOPIC_ID as c_TOPIC_ID,c.TOPIC_SORT as c_TOPIC_SORT,c.EXAM_ID as c_EXAM_ID
        from gha_ex_exam_group a left join gha_ex_exam b on a.ID_ = b.GROUP_ID and b.ISDELETED = '0'
        left join gha_ex_exam_question_sort c on b.ID_ = c.EXAM_ID and c.ISDELETED = '0'
        <where>
            a.ISDELETED = '0'
            <if test="nameAndId != null and nameAndId != ''">
                and (b.EXAM_NAME like concat('%',#{nameAndId},'%') or b.ID_ = #{nameAndId})
            </if>
            <if test="keyWord !=null and keyWord != ''">
                 and b.EXAM_NAME like concat('%',#{keyWord},'%')
            </if>
            <if test="conditions != null">
                and (
                <foreach collection="conditions" item="entity" separator="or">
                    b.EXAM_STATUS = #{entity}
                </foreach>
                )
            </if>
            <if test="peopleType != null and peopleType == 1">
                <if test="userIds != null">
                    and (
                    <foreach collection="userIds" item="entity" separator="or">
                         b.PUBLIC_PEOPLE = #{entity}
                    </foreach>
                    )
                </if>
            </if>
            <if test="peopleType != null and peopleType == 2">
                <if test="userIds != null">
                    and (
                    <foreach collection="userIds" item="entity" separator="or">
                         b.OPER = #{entity}
                    </foreach>
                    )
                </if>
            </if>
            <if test="examId != null">
                 and b.ID_ = #{examId}
            </if>
        </where>
        order by a.OPTIME desc ,b.OPTIME desc
    </select>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值