SELECT p.PRODUCTID AS PRODUCTID, p.NAME AS NAME, p.DESCRIPTION AS DESCRIPTION, p.IMAGE AS IMAGE, p.CATEGORYID AS CATEGORYID FROM Product p INNER JOIN Category c ON c.categoryId=p.categoryId INNER JOIN Item i ON i.productId = p.productId WHERE c.categoryId IN ('ACTADV') AND p.name LIKE '' AND p.description LIKE '' AND i.name LIKE '' AND i.description LIKE ''
위의 쿼리문을 아래와 같이 동적으로 처리,
parameterClass에 해당하는 beans(productSearch)를 만들어 이용한다.
<select id="searchProductsWithProductSearch" parameterClass="productSearch" resultClass="product" > SELECT DISTINCT p.PRODUCTID, p.NAME, p.DESCRIPTION, p.IMAGE, p.CATEGORYID FROM Product p <isEqual property="itemProperties" compareValue="true"> INNER JOIN Item i ON i.productId=p.productId </isEqual> <dynamic prepend="WHERE"> <iterate property="categoryIds" open="p.categoryId IN (" close=")" conjunction="," prepend="BOGUS"> #categoryIds[]# </iterate> <isNotEmpty property="productName" prepend="AND"> p.name LIKE #productName# </isNotEmpty> <isNotEmpty property="productDescription" prepend="AND"> p.description LIKE #productDescription# </isNotEmpty> <isNotEmpty property="itemName" prepend="AND"> i.name LIKE #itemName# </isNotEmpty> <isNotEmpty property="itemDescription" prepend="AND"> i.description LIKE #itemDescription# </isNotEmpty> </dynamic> </select>source : iBATIS 인 액션
'DataBase' 카테고리의 다른 글
mybatis - LIKE절에 parameter값 넣기 (0) | 2011.04.12 |
---|
Recent Comments