ibatis 数组参数(IBatisNet)

 第一种:传入参数仅有数组

 

       <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
List的用于遍的元素(必
open
整个遍内容体始的字符串,用于定括号(可
close
-整个遍内容体束的字符串,用于定括号(可
conjunction
次遍内容之的字符串,用于定ANDOR(可
<iterate>
历类List的元素。

你可能感兴趣的:(ibatis 数组参数(IBatisNet))