DBILITY

mybatis foreach multiple like 본문

java/mybatis

mybatis foreach multiple like

DBILITY 2023. 11. 30. 18:36
반응형

갑자기 필요해서 해봤다.

paramter로 array를 사용함. 과목명과 교육목표에 특정 키워드들이 들어 갔는지 조회하는 부분에 사용...

<foreach collection="subjects" index="index" item="item" open=" AND (" close=")" separator=" ">
    <choose>
       <when test="index==0">
          B.SUBJECT_NAME LIKE '%${item}%'
          OR C.EDUC_GOAL LIKE '%${item}%'
       </when>
       <otherwise>
          OR B.SUBJECT_NAME LIKE '%${item}%'
          OR C.EDUC_GOAL LIKE '%${item}%'
       </otherwise>
    </choose>
</foreach>

하고 보니 static...

<foreach collection="subjects" index="index" item="item" open=" AND (" close=")" separator=" ">
    <choose>
       <when test="index==0">
          B.SUBJECT_NAME LIKE '%#'+#{item}+'%'
          OR C.EDUC_GOAL LIKE '%#'+#{item}+'%'
       </when>
       <otherwise>
          OR B.SUBJECT_NAME LIKE '%'+#{item}+'%'
          OR C.EDUC_GOAL LIKE '%'+#{item}+'%'
       </otherwise>
    </choose>
</foreach>
반응형
Comments