zoukankan      html  css  js  c++  java
  • ibatis中in语句参数传入方法

    第一种:传入参数仅有数组,iterate中不能有数组的属性名
           <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 ); 

           第二种:传入参数有数组,且有其他数据,iterate中必须有数组的属性名
            <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传入,不需要iterate循环,TestIn是对象,所以需要property属性,假如参数是String类型的,就不需要property属性
            <select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_"> 
                select * 
                from MailInfo with (nolock) 
                where ID in 

        <isNotEmpty prepend="AND" property="StrValue"
                ($StrValue$) 

        </isNotEmpty>
            </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的元素。

  • 相关阅读:
    c# 获取iis地址
    c# 导入导出Excel
    ffmpeg 转成MP3采样率8000
    c# 百度api语音识别
    c# 文件转换成base64
    js截取文件的名称
    js checkbox获取选中的值
    js base64位和c# Base64位转换
    笨方法学Python——习题16
    Python学习问题
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/8525085.html
Copyright © 2011-2022 走看看