ibatis in语句参数传入方法
2015-11-04 16:33
381 查看
第一种:传入参数仅有数组
<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的元素。
相关文章推荐
- ibatis简单实现与配置
- ibatis 的缓存
- 简单实现ibatis的物理分页
- ibatis加memcached缓存
- ibatis 高速缓存
- 最近在用ibatis,发些文章来学习下
- 学习ibatis,参照夏晰翻译的ibatis2.0学习指南
- 从IBatis2.X 移植到IBatis3.0 sqlMapConfig and sqlMap XML 配置文件升级说明
- iBATIS教程之快速入门浅析
- struts2.1.8+mybatis3.0+spring3.0(全注解)小例子
- iBatis2--SqlMap的配置总结
- ibatis 动态Sql
- Hibernate和ibatis在同一个webapp中混合使用在spring中的配置方法
- How to use custom type handler (typeHandler) in ibatis 2.3.4
- iBatis 配置文件详解
- ibatis中#和$用法区别
- ibatis 直接升格为 apache 一级项目了
- 做Web开发真累
- ibatis+mysql的中文乱码问题
- struts框架下ibatis配置文件