日期:2014-05-16  浏览次数:20733 次

关于ibatis如何传入数组作为参数

转载:感谢 涂剑凯
http://blog.sina.com.cn/bdstjk

?

一:传入参数仅有数组

???????<select id="GetEmailList_Test"??resultClass="EmailInfo_">
????????????select *
????????????from MailInfo with (nolock)
????????????where ID in
????????????????<iterate open="(" close=")" conjunction="," >
????????????????????#[]#
????????????????</iterate>
????????</select>

java代码:

????????????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>

java代码:

????????????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; }
????????}