ibatis遍历数组

来源:互联网 发布:csgo淘宝买饰品 编辑:程序博客网 时间:2024/06/11 23:15

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

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

0 0