DBILITY

독거 가능성 100% 노후에 라면값이라도 하게 센스를 발휘합시다!😅
Please click on the ad so that I can pay for ramen in my old age!
点击一下广告,让老后吃个泡面钱吧!
老後にラーメン代だけでもするように広告を一回クリックしてください。

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