ibatis in語句引數傳入方法
第一種:傳入引數僅有陣列
<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 -型別為java.util.List的用於遍歷的元素(必選)
open -整個遍歷內容體開始的字串,用於定義括號(可選)
close -整個遍歷內容體結束的字串,用於定義括號(可選)
conjunction -每次遍歷內容之間的字串,用於定義AND或OR(可選)
<iterate>遍歷型別為java.util.List的元素。
<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 -型別為java.util.List的用於遍歷的元素(必選)
open -整個遍歷內容體開始的字串,用於定義括號(可選)
close -整個遍歷內容體結束的字串,用於定義括號(可選)
conjunction -每次遍歷內容之間的字串,用於定義AND或OR(可選)
<iterate>遍歷型別為java.util.List的元素。
相關文章
- Linux下邏輯測試語句引數和流程控制語句 if語句Linux
- Ruby方法傳不定引數
- c# 方法引數(傳值,傳引用,ref,out,params,可選引數,命名引數)C#
- Java入門第12天 (方法過載 ,方法的引數傳遞)Java
- mybatis 傳入多個引數MyBatis
- gdb除錯傳入引數除錯
- Java方法04:命令列傳遞引數、可變引數Java命令列
- Mybatis 傳入多個引數查詢資料 (3種方法)MyBatis
- 把介面當作引數傳入
- Mybatis傳入引數為List物件MyBatis物件
- JS的方法引數傳遞(按值傳遞)JS
- 淺析MySQL語句優化中的explain引數MySql優化AI
- mybatis 的傳入引數如何既有物件又有單個引數MyBatis物件
- Go語言引數傳遞是傳值?還是傳引用 ?Go
- GridView傳遞兩個引數的方法View
- Python語法—函式及引數傳遞Python函式
- GO語言————6.3 傳遞變長引數Go
- 向路由元件傳遞引數2種方法路由元件
- php函式引用傳遞引數的方法PHP函式
- MyBatis中傳入引數為List集合的MyBatis
- Mybatis parameterType 傳入多個引數的使用MyBatis
- python怎麼傳入不確定引數Python
- go語言引數傳遞到底是傳值還是傳引用Go
- 引數傳遞
- DropDownListFor傳引數
- Javascript 定時器呼叫傳遞引數的方法JavaScript定時器
- OC-從記憶體角度理解block可作為方法傳入引數的原因記憶體BloC
- ts中如何限制方法傳入的引數data必須是陣列,且為偶數項?陣列
- ABAP 方法呼叫的引數傳遞裡,透過引用傳遞的方式,能修改原始引數值嗎?
- 一個UPDATE語句引發的血案
- 如何一條Mediainfo --Inform語句同時獲取視訊引數和音訊引數多個ParametersAIORM音訊
- sql宣告變數,及if -else語句、while語句的用法SQL變數While
- Jmeter 跨執行緒組引數傳遞的方法JMeter執行緒
- SSM框架中Mybatis傳遞引數的幾種方法SSM框架MyBatis
- mybatis如何傳引數MyBatis
- Mybatis引數傳遞MyBatis
- 15.MyBatis傳入多個引數的問題MyBatis
- SpringJpa @query 中根據傳入引數(欄位)排序Spring排序
- 入門MySQL——DML語句篇MySql