关于ibatis如何传入数组作为参数
转载:感谢 涂剑凯
http://blog.sina.com.cn/bdstjk
?
一:传入参数仅有数组
???????<select id="GetEmailList_Test"??resultclose=")" conjunction="," >
????????????????????#[]#
????????????????</iterate>
????????</select>
java代码:
????????????string[] strValue = new string[] { "1", "2", "3" };
????????????Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test", strValue );
二:传入参数有数组,且有其他数据
????????<select id="GetEmailList_Test3" parameterresultclose=")" 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; }
????????}
????}
?
????????<select id="GetEmailList_Test2" parameterresultClass="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的元素。