프로그래머의 삶 Programmer's Life/PersistanceSolution

다이나믹쿼리~ by iBatis

Oliver's World 2008. 11. 5. 10:51
728x90

---다이나믹쿼리------------------------------------------

 

 <statement id="UserLikeGenre" resultClass="common.bean.Genre">
  SELECT * FROM GENRE
  <dynamic prepend="WHERE">
   <isNotEmpty prepend="OR" property="genrename1">
    GENRENAME LIKE '%$genrename1$%'
   </isNotEmpty>
   <isNotEmpty prepend="OR" property="genrename2">
    GENRENAME LIKE '%$genrename2$%'
   </isNotEmpty>
   <isNotEmpty prepend="OR" property="genrename3">
    GENRENAME LIKE '%$genrename3$%'
   </isNotEmpty>
   <isNotEmpty prepend="OR" property="genrename4">
    GENRENAME LIKE '%$genrename4$%'
   </isNotEmpty>
   <isNotEmpty prepend="OR" property="genrename5">
    GENRENAME LIKE '%$genrename5$%'
   </isNotEmpty>
  </dynamic>
 </statement>

 

값이 비어있지 않다면 생성해준다~

 

statement 를사용하면 '$$' 로 해야 하며~ %%로 검색하기 위해서

statement를 사용

 

 

---간단한 select 문------------------------------------------

 

<select id="UserCouponeCheck" resultClass="common.bean.Coupone">
  SELECT * FROM COUPONE WHERE ID=#id# AND COUPONEENDDAY
  <![CDATA[>]]>           <-- 요놈은 xml 검증 무시~하기 위해
  SYSDATE
 </select>

 

 

 

---간단한 insert 문------------------------------------------

 

 <insert id="UserInsertGenre">
  INSERT INTO MEM_LIKEGENRE(MEMLIKEGENRENO, ID, GENRECODE)
  VALUES(MEM_LIKEGENRE_SEQ.NEXTVAL,#id#,#likegenreno#)
 </insert>

 

 

---간단?한 update 문---------------------------------------

 

 <statement id="UserUpdate">
  UPDATE MEMBER SET
  ID='$id$',NAME='$name$',PASSWORD='$password$',SSN='$ssn$',
  DETAILADDR='$detailaddr$',PHONE='$phone$',EMAIL='$email$',
  BIRTHDAY=TO_DATE('$birthday$','yy/mm/dd'),
  MILEAGE='$mileage$',SEQ='$seq$' WHERE ID LIKE '%$id$%' AND
  PASSWORD LIKE '%$password$%' AND ssn LIKE '%$ssn$%'
 </statement>

 

728x90