例子一
查詢條件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$%'
</dynamic>
</select>
在查詢條件中有一個數組stuIds,在動态标簽中進行周遊,看每一個student的id是否在該數組中。
發出的語句 select id,name from student where id in ( ? , ?) ...
例子二
private List<Student> lst;
<isNotNull property="lst" prepend="and">
<iterate property="lst" open=" (" close=")" conjunction="or">
id = #lst[].id#
發出的語句 select id,name from student where (id = ? or id = ?)...
本文轉自IT徐胖子的專欄部落格51CTO部落格,原文連結http://blog.51cto.com/woshixy/1021972如需轉載請自行聯系原作者
woshixuye111