반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[mybatis] if else 혹은 switch case 본문

JAVA/mybatis

[mybatis] if else 혹은 switch case

닉의네임 2022. 5. 9. 10:11
반응형

우선 if 문

<select id="findBoardList" resultType="boardList">

	select * from tbl_board
    where title = '%'||#{title}||'%'
    <if test="content != null">
    	OR content = '%'||#{content}||'%'
    </if>

</select>

and or 조건문 

<if test="parameter1 != null and parameter2 != null">

<if test="parameter1 != null or parameter2 != null">

<if test='parameter1 == "string" and parameter2 == "string"'>

<if test='parameter1 != null and parameter2.equals("string")'>

<if test="parameter1 != null and parameter2.equals('string')">

switch case 

<choose>
    <when test="storeType == 'DOO'">-- doo 인 경우 재고수량
        , iisales.remain_cnt -- 재고수량
    </when>
    <otherwise> 
        , (SELECT remain_cnt FROM itm_item_sales WHERE item_no = ii .item_no
        AND if (iiss.stock_allot_type = 'ALL' <![CDATA[&&]]>
        iiss. online_stock_yn ='Y' <![CDATA[&&]]>
        iiss. online_stock_start_dt  <![CDATA[<=]]> now() <![CDATA[&&]]>
        now() <![CDATA[<=]]> iiss. online_stock_end_dt
        <choose>
            <when test="storeType == 'EOO'"> 
                , store_id ='99998'
            </when>
            <otherwise> 
                , store_id ='99999'
            </otherwise>
        </choose>
        , store_id =  iisd.store_id ) ) AS remain_cnt
    </otherwise>
</choose>
반응형
Comments