2_mybatis_(다중조건검색)

study/mybatis · 2020. 2. 17. 09:04

<where></where>

-where 엘리먼트 내부에 작성된 SQL 구문의 시작부분에 

where가 없다면 자동으로 where 구문추가, 또는 시작 부분의 SQL이 AND 또는

OR일 경우 이를 제거하고 where를 추가함

<select id="selectSearchList2" parameterType="map" 
	resultMap="boardResultSet">
	<!-- _parameter : 전달받은 파라미터 -->
	<bind name="sv" value="'%' + _parameter.searchValue + '%'"/>
	<!-- 조회되는 필드명과 vo의 필드명이 달라서 resultMap으로 매핑해줌-->
	SELECT BOARD_NO, BOARD_TITLE, BOARD_COUNT,
			BOARD_MODIFY_DT, MEMBER_ID, CATEGORY_NM
	FROM V_BOARD
	<where>
		<choose>
			<when test="searchKey == 'title'">
				AND BOARD_TITLE LIKE #{sv}
			</when>
			<when test="searchKey == 'content'">
				AND BOARD_CONTENT LIKE #{sv}
			</when>
			<otherwise>
				AND (BOARD_TITLE LIKE #{sv}
				OR BOARD_CONTENT LIKE #{sv})
			</otherwise>
				
		</choose>
		<if test="searchCategory != null">
			AND CATEGORY_NM IN
			<foreach index="index" item="item" collection="searchCategory"
				open="(" separator="," close=")">
				#{item}
			</foreach>	
		</if>
		AND	BOARD_TYPE=1
	</where>
		
</select>

 

 

'study > mybatis' 카테고리의 다른 글

1_mybatis_흐름  (0) 2020.02.13
0_mybatis_세팅,개요  (0) 2020.02.12