ibatis中iterate的用法(conjunction="or" ",")


例子一

 

查詢條件dto

public class queryCondition
{
 private String[] stuIds;
 private String name;
}


查詢sqlMap

<select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
 select id,name from student
 <dynamic prepend="where">
  <isNotNull property="stuIds" prepend="and">
   <iterate property="stuIds" open="id in (" close=")" conjunction=",">
    #stuIds[]#
   </iterate>
  </isNotNull>
  <isNotNull property="name" prepend="and">
   name like '%$name$%'
  </isNotNull>
 </dynamic>
</select>


在查詢條件中有一個數組stuIds,在動態標簽中進行遍歷,看每一個student的id是否在該數組中。

發出的語句 select id,name from student where  id in ( ? , ?) ...  

 

 

例子二 

 

查詢條件dto

public class queryCondition
{
 private List<Student> lst;
 private String name;
}


查詢sqlMap

<select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
 select id,name from student
 <dynamic prepend="where">
  <isNotNull property="lst" prepend="and">
   <iterate property="lst" open=" (" close=")" conjunction="or">
    id = #lst[].id#
   </iterate>
  </isNotNull>
  <isNotNull property="name" prepend="and">
   name like '%$name$%'
  </isNotNull>
 </dynamic>
</select>

 

發出的語句 select id,name from student where  (id = ?   or   id = ?)...


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM