본문으로 바로가기

MyBatis 에서 여러 파라미터 값 비교를 통한 조건문

category SPRING/MyBatis 2021. 9. 7. 21:59
728x90
반응형
SMALL

   

<choose>
     <when test='project_title != "0" and project_title != "1" and project_title != "2" ' >
    and P.PROJECT_TITLE=#{project_title}
    </when>
     <when test='project_title == "1"'>
    and P.PROJECT_TITLE IS NULL
    </when>
 </choose>

 

풀 sql 문

<!-- 진행중 -->
<select id="getIngMyJobById" resultMap="jobVO" >
SELECT J.ID ,J.DEEP ,J.PROJECT_ID,J.NAME, J.start_date, J.END_DATE ,J.TOTAL_ONE_MD,
   J.PLAN_ONE_MD, J.TOTAL_DATE, J.PLAN_DATE, J.MANAGER, J.REAL_START_DATE, 
       J.REAL_END_DATE, J.REPORT, J.PLAN_PROGRESS, J.REAL_PROGRESS, J.JOB_ID,
       J.PRIVACY_STATE,
       P.STATE, P.PROJECT_TITLE, P.PROJECT_NICKNAME
       
FROM JOB J left join PROJECT P on (J.PROJECT_ID =P.ID) 
WHERE J.MANAGER = (
 SELECT  NAME FROM USER U
 WHERE U.ID = #{userid}
    )and J.PRIVACY_STATE=112
     <choose>
     <when test='project_title != "0" and project_title != "1" and project_title != "2" ' >
    and P.PROJECT_TITLE=#{project_title}
    </when>
     <when test='project_title == "1"'>
    and P.PROJECT_TITLE IS NULL
    </when>
    </choose>
728x90
반응형
LIST