当前位置:   article > 正文

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

mybatis 集合or语句
  1. <if test="peopleType != null and peopleType == 1">
  2. <if test="userIds != null">
  3. and (
  4. <foreach collection="userIds" item="entity" separator="or">
  5. b.PUBLIC_PEOPLE = #{entity}
  6. </foreach>
  7. )
  8. </if>
  9. </if>

完整

  1. <select id="examQuery" resultMap="GhaExExamQueryDTOMap">
  2. select
  3. a.ID_ as groupID, a.GROUP_NAME as groupName, b.ID_,b.ISDELETED,b.TENANTID,b.OPTIME,b.OPER,b.CANCEL_TIME,
  4. b.UPDATETIME,b.UPDATOR,b.GROUP_ID,b.EXAM_NAME,b.EXPLAINS,b.PUBLIC_PEOPLE,b.PUBLIC_TIME,b.EXAM_STATUS,b.RECYCLE_IS,
  5. (select count(1) from gha_ex_my_exam where EXAM_ID = b.ID_) as answerNumber,
  6. 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
  7. from gha_ex_exam_group a left join gha_ex_exam b on a.ID_ = b.GROUP_ID and b.ISDELETED = '0'
  8. left join gha_ex_exam_question_sort c on b.ID_ = c.EXAM_ID and c.ISDELETED = '0'
  9. <where>
  10. a.ISDELETED = '0'
  11. <if test="nameAndId != null and nameAndId != ''">
  12. and (b.EXAM_NAME like concat('%',#{nameAndId},'%') or b.ID_ = #{nameAndId})
  13. </if>
  14. <if test="keyWord !=null and keyWord != ''">
  15. and b.EXAM_NAME like concat('%',#{keyWord},'%')
  16. </if>
  17. <if test="conditions != null">
  18. and (
  19. <foreach collection="conditions" item="entity" separator="or">
  20. b.EXAM_STATUS = #{entity}
  21. </foreach>
  22. )
  23. </if>
  24. <if test="peopleType != null and peopleType == 1">
  25. <if test="userIds != null">
  26. and (
  27. <foreach collection="userIds" item="entity" separator="or">
  28. b.PUBLIC_PEOPLE = #{entity}
  29. </foreach>
  30. )
  31. </if>
  32. </if>
  33. <if test="peopleType != null and peopleType == 2">
  34. <if test="userIds != null">
  35. and (
  36. <foreach collection="userIds" item="entity" separator="or">
  37. b.OPER = #{entity}
  38. </foreach>
  39. )
  40. </if>
  41. </if>
  42. <if test="examId != null">
  43. and b.ID_ = #{examId}
  44. </if>
  45. </where>
  46. order by a.OPTIME desc ,b.OPTIME desc
  47. </select>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/158299
推荐阅读
相关标签
  

闽ICP备14008679号