Posted on 2012-02-03 10:11
yuhaibo736 閱讀(16609)
評論(1) 編輯 收藏
第一種:傳入參數僅有數組
<select id="GetEmailList_Test" resultClass="EmailInfo_">
select *
from MailInfo with (nolock)
where ID in
<iterate open="(" close=")" conjunction="," >
#[]#
</iterate>
</select>
調用
string[] strValue = new string[] { "1", "2", "3" };
Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test", strValue );
第二種:傳入參數有數組,且有其他數據
<select id="GetEmailList_Test3" parameterClass="TestIn" resultClass="EmailInfo_">
select top(#Count#)*
from MailInfo with (nolock)
where ID in
<iterate open="(" close=")" conjunction="," property="ArrValue" >
#ArrValue[]#
</iterate>
</select>
調用
TestIn ti = new TestIn();
ti.Count = 1;
ti.ArrValue = strValue;
return Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test3", ti);
實體類:
public class TestIn
{
private int count;
public int Count
{
get { return count; }
set { count = value; }
}
private string[] arrValue;
public string[] ArrValue
{
get { return arrValue; }
set { arrValue = value; }
}
}
第三種:in后面的數據確定,使用string傳入
<select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_">
select *
from MailInfo with (nolock)
where ID in
($StrValue$)
</select>
調用
Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test2", "1,2,3");
其他信息:
Iterate的屬性:
prepend -可被覆蓋的SQL語句組成部分,添加在語句的前面(可選)
property -類型為java.util.List的用于遍歷的元素(必選)
open -整個遍歷內容體開始的字符串,用于定義括號(可選)
close -整個遍歷內容體結束的字符串,用于定義括號(可選)
conjunction -每次遍歷內容之間的字符串,用于定義AND或OR(可選)
<iterate>遍歷類型為java.util.List的元素。