[Spring] Mybatis <if>

Wintering·2022년 9월 19일
0

참고링크

if

조건식이 참인 경우 쿼리문을 실행
전달받은 파라미터 값에 따라 쿼리를 동적으로 변할 수 있게 하는 역할
주로, where의 일부로 포함하여 사용

if 태그의 test 속성 값으로 논리 연산자 (>, >=, <=, ==, !=)를 사용한 조건식을 삽입
태그 안에는 조건식이 true일 경우 실행되어야 할 쿼리를 작성한다.

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

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

</select>

0개의 댓글