반응형

Where 1=1 처럼 동적으로 set 컬럼을 바꾸고 싶을때

 

방법1. Mybatis 해결 : <set> 사용 (추천)

        <set>

            <if test="meterChangeUsage != null and meterChangeUsage !=''">

                gmp.METER_CHANGE_USAGE = #{meterChangeUsage} ,

            </if>

            <if test="meterChangeDt != null and meterChangeDt !=''">

                gmp.METER_CHANGE_DT = #{meterChangeDt} ,

            </if>

            <if test="contractMethod != null and contractMethod !=''">

                gai.CONTRACT_METHOD = #{contractMethod} ,

            </if>

            <if test="contractCapacity != null and contractCapacity !=''">

                gai.CONTRACT_CAPACITY = #{contractCapacity} ,

            </if>

        </set>

 

방법2. 쿼리로 해결 : 바꾸려는 컬럼을 기존 값으로  번더 사용     (비추) 

            set gmp.METER_CHANGE_USAGE =  gmp.METER_CHANGE_USAGE

            <if test="meterChangeUsage != null and meterChangeUsage !=''">

                gmp.METER_CHANGE_USAGE = #{meterChangeUsage} ,

            </if>

            <if test="meterChangeDt != null and meterChangeDt !=''">

                gmp.METER_CHANGE_DT = #{meterChangeDt} ,

            </if>

            <if test="contractMethod != null and contractMethod !=''">

                gai.CONTRACT_METHOD = #{contractMethod} ,

            </if>

            <if test="contractCapacity != null and contractCapacity !=''">

                gai.CONTRACT_CAPACITY = #{contractCapacity} ,

            </if>

 

<set> 사용시 마지막 ,(콤마) 자동적으로 제거

 

반응형

+ Recent posts