본문 바로가기
코딩일기/날씨앱 만들기 프로젝트

[MySQL] Mybatis 동적 쿼리문

by 욱파이어니어 2022. 1. 27.
728x90
반응형

가끔씩 값에 따라서 쿼리문을 다르게 해야할때가 있다.

그럴땐 아래와 같이 동적쿼리문을 작성해주면 된다.

 

	<select id="아이디" resultMap="resultMap" parameterType="파라미터값">
		<if test="파라미터변수 == 1">
			select address, temp_code from region_code where address = #{address}
		</if>
		<if test="파라미터변수 == 2">
			select address, fc_code from region_code where address = #{address}
		</if>
	</select>

 

위 와 같이 

<if> 를 이용하고 test 안에 조건문을 넣어주면 된다.

 

반응형