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的元素。
ibatis中in语句参数传入方法的更多相关文章
- iBatis in 语句参数传入方法
刚刚开始在工作中用到iBatis 在用到in去查询或者删除 我本来是传递一个String的参数,但是总是报以下的错误
- ibatis in语句参数传入方法
第一种:传入参数仅有数组 <select id="GetEmailList_Test" resultClass="EmailInfo_"& ...
- Struts2中Action接收参数的方法
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt112 Struts2中Action接收参数的方法主要有以下三种: 1.使用A ...
- Struts2中Action接收参数的方法主要有以下三种:
Struts2中Action接收参数的方法主要有以下三种: 1.使用Action的属性接收参数(最原始的方式): a.定义:在Action类中定义属性,创建get和set方法: b.接 ...
- ibatis中使用List作为传入参数的使用方法及 CDATA使用
ibatis中list做回参很简单,resultClass设为list中元素类型,dao层调用: (List)getSqlMapClientTemplate().queryForList(" ...
- Ibatis中传List参数
Ibatis中用list传参数的方式. Java代码 select count(id) from `user` where id in #[]# and status=1 . <select ...
- Java中可变长参数的方法
原文转自:http://www.cnblogs.com/lanxuezaipiao/p/3190673.html 在Java5 中提供了变长参数(varargs),也就是在方法定义中可以使用个数不确定 ...
- C#中SQL语句参数写法
OracleConnection oc=new OracleConnection("data source=osserver;User Id=****;password=**"); ...
- SpringMVC中重定向传参数的方法
在spring的一个controller中要把参数传到页面,只要配置视图解析器,把参数添加到Model中,在页面用el表达式就可以取到.但是,这样使用的是forward方式,浏览器的地址栏是不变的,如 ...
随机推荐
- Orchard运用 - 学习资源分享
这段时间研究Orchard,看到一些资源十分有用. 比如国内还是有些牛人在分享心得,在此也广播一下给新手: JustRun对Orchard的一些代码分析 Orchard源码分析 Orchard中文社区 ...
- make&&gcc/g++ 生成 map file
map file 对于嵌入式开发是非常有用的,尤其是当你开发的module引起了 kernel panic 的时候. 仅写作Mark用 make: $vim makefile (add " ...
- c#如何操作ppt的播放 【转】
C#控制ppt的代码 包括打开ppt文件.读取幻灯页,插入幻灯片,自动播放等 using System.Collections.Generic; using System.Linq; using Sy ...
- Python 高级图像处理
构建图像搜索引擎并不是一件容易的任务.这里有几个概念.工具.想法和技术需要实现.主要的图像处理概念之一是逆图像查询(RIQ).Google.Cloudera.Sumo Logic 和 Birst 等公 ...
- Python-urllib学习记录
urllib是python自带库,不要专门安装,还挺好用的. 脚本语言的好处之一就是随写随用,有些东西用C语言写真的是能把人累死,换成python就是几行代码,so easy,对于喜欢偷懒的同学绝对是 ...
- Android编译程序报错:Re-installation failed due to different application signatures.
如果机子上已经安装非本机编译的android程序,在编译的时候就会报错.方法首选的是删除原程序,然后再进行编译. 但是有一部分程序是烧录在系统程序里面的,无法直接删除,这时候可以使用adb shell ...
- android-关于友盟的自动版本更新(面向小白)
今天说一下关于友盟的自动版本更新(傻瓜式版本更新) 关于自动更新的话,如果让android程序猿自己写的话还是不是那么简单的(对于我这个菜鸟来说...),又要检查当前版本,又要在服务器存储新的版本,又 ...
- grid control 11.1.0.1 安装指南
grid control 11.1.0.1 安装指南 废话少说,进入正题 系统版本号 [root@gridcontrol ~]# lsb_release -a LSB Version: :bas ...
- poj 2406 Power Strings KMP匹配
对于数组s[0~n-1],计算next[0~n](多计算一位). 考虑next[n],如果t=n-next[n],如果n%t==0,则t就是问题的解,否则解为1. 这样考虑: 比方字符串"a ...
- win10 你没有足够的权限执行此操作。
win10 你没有足够的权限执行此操作. CreateTime--2018年4月21日08:21:31 Author:Marydon 鼠标悬浮到windows图标上,右键-->选择:以命令提 ...