본문 바로가기

백엔드/myBatis

[3.0] like 검색.

- iBatis 3.0 에서 간단하게 like 검색 하는 법

CB.CUSTOMER_NAME like CONCAT('%', #{customerName:VARCHAR}, '%')

사용 예 )
<-select id="expired_search" parametertype="java.util.HashMap" resulttype="net.autobrain.domain.ExpiredSearchResult" flushcache="false" usecache="false">
SELECT CB.COUPON_BOOK_NO, CN.COUPON_NAME_SEQ, CN.COUPON_NAME
		    , CASE WHEN CB.CHARGE_TYPE = 'F' THEN '무상' ELSE '유상' END AS CHARGE_TYPE
		    , AM.AUTO_MODEL_SEQ
		    , AM.MODEL_NAME
		    , IFNULL(CB.CAR_NUMBER, '') AS CAR_NUMBER
		    , CB.VIN_NO
		    , CB.CUSTOMER_NAME
		    , CONCAT(CB.CUSTOMER_PHONE_1, '-', CB.CUSTOMER_PHONE_2, '-', CB.CUSTOMER_PHONE_3) AS CUSTOMER_PHONE
		    , CB.AUTO_SALES_USER_SEQ
		    , SU.USER_NAME
		    , CB.COUPON_EXPIRED_DATE
		FROM COUPON_BOOK CB
		    INNER JOIN COUPON CP ON CP.COUPON_BOOK_SEQ = CB.COUPON_BOOK_SEQ
		    INNER JOIN COUPON_BOOK_SETUP CBS ON CBS.COUPON_BOOK_SETUP_SEQ = CB.COUPON_BOOK_SETUP_SEQ
		    INNER JOIN COUPON_NAME CN ON CN.COUPON_NAME_SEQ = CBS.COUPON_NAME_SEQ
		    INNER JOIN COUPON_SETUP CS ON CBS.COUPON_BOOK_SETUP_SEQ = CS.COUPON_BOOK_SETUP_SEQ
		    INNER JOIN AUTO_MODELS AM ON CBS.AUTO_MODEL_SEQ = AM.AUTO_MODEL_SEQ
		    INNER JOIN AUTO_CLASSES AC ON AM.AUTO_CLASS_SEQ AND AC.AUTO_CLASS_SEQ
		    INNER JOIN SALES_USERS SU ON SU.SALES_USER_SEQ = CB.AUTO_SALES_USER_SEQ
		    INNER JOIN SHOWROOM_CODES SC ON SU.SHOWROOM_SEQ = SC.SHOWROOM_SEQ
		WHERE CB.REFUND_DATE IS NULL AND CB.DISABLE IS NULL
		AND CN.COUPON_NAME_SEQ = #{couponNameSeq}
		AND CB.CUSTOMER_NAME like CONCAT('%', #{customerName:VARCHAR}, '%')
	        AND DATE_FORMAT(#{beginCriterionDate}, '%Y-%m-%d') <= DATE_FORMAT(DATE_SUB(CB.COUPON_EXPIRED_DATE, INTERVAL #{gubun} DAY), '%Y-%m-%d')
		AND DATE_FORMAT(DATE_SUB(CB.COUPON_EXPIRED_DATE, INTERVAL #{gubun} DAY), '%Y-%m-%d') <= DATE_FORMAT(#{endCriterionDate}, '%Y-%m-%d')
		AND (TO_DAYS(CB.COUPON_EXPIRED_DATE) - TO_DAYS(CAST(#{criterionDate} AS DATE)) BETWEEN #{criterionDay1:NUMERIC} AND #{criterionDay2:NUMERIC})
		GROUP BY COUPON_BOOK_NO
    <-/select>

'백엔드 > myBatis' 카테고리의 다른 글

프로시저 호출 시 주의 할 점..  (0) 2012.11.13
iBatis isEqual  (0) 2012.11.05
[3.0] forEach 사용  (0) 2010.07.15
[3.0] JDBC Type  (0) 2010.07.09
iBatis 3.0 Cache 문제 -  (0) 2010.07.08