ibatis 多种传参方式
1,在公司项目yuda遇到的传入in语句,如果直接拼接in语句:in (....),sqlmap中使用#...#输出是不行的。
为需要使用:
第三种: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");
参考自:https://blog.csdn.net/yangkai_hudong/article/details/25130555
一下内容来自参考:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
第一种:传入参数仅有数组
<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的元素。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2,使用hashmap传参
虽然ibatai sql map可以配置多个参数,但sqlMap只能传入一个参数,我们有两种方式,一是把我们的参数封装成一个类,通过set/get取值的方式给sql map注入参数,二是通过hashMap(可以组合一些不是同一个pojo的参数有优势)
<select id="getPeopleList" resultClass="model.User" parameterClass="java.util.Map">
<![CDATA[
select * from test where name like '%$name$%'
]]>
</select>
Map map=new HashMap();
map.put("name", "gaoxiang"); key为参数名,value位数据
List list = sqlMap.queryForList("getPeopleList", map);
在这里注意ibatis中#和$符号的区别:https://blog.csdn.net/geyouchao/article/details/51817747
https://blog.csdn.net/kiss_vicente/article/details/7602900
ibatis 多种传参方式的更多相关文章
- PHP四种传参方式
test1界面: <html> <head> <title>testPHP</title> <meta http-equiv = "co ...
- python 计算机发展史,线程Process使用 for循环创建 2种传参方式 jion方法 __main__的解释
########################总结################## #一 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬 ...
- Vue中router两种传参方式
Vue中router两种传参方式 1.Vue中router使用query传参 相关Html: <!DOCTYPE html> <html lang="en"> ...
- axios的各种传参方式
axios的各种传参方式 1. params方式 axios({ url: '/users', method: 'get', params: { id: '11111', name: '22222' ...
- vue param和query两种传参方式
1.传参方式 query传参方式 this.$router.push({ path: "/home", query: {code:"123"} }) param ...
- 浅谈C++三种传参方式
浅谈C++三种传参方式 C++给函数传参中,主要有三种方式:分别是值传递.指针传递和引用传递. 下面通过讲解和实例来说明三种方式的区别. 值传递 我们都知道,在函数定义括号中的参数是形参,是给函数内专 ...
- Mybatis的几种传参方式,你了解吗?
持续原创输出,点击上方蓝字关注我 目录 前言 单个参数 多个参数 使用索引[不推荐] 使用@Param 使用Map POJO[推荐] List传参 数组传参 总结 前言 前几天恰好面试一个应届生,问了 ...
- vector作为参数的三种传参方式
c++中常用的vector容器作为参数时,有三种传参方式,分别如下(为说明问题,用二维vector): function1(std::vector<std::vector<int> ...
- vue的三种传参方式
<template> <div> <router-link :to="{'name':'x',params:{'type':'users'}}"> ...
随机推荐
- vue打包项目后使用-webkit-line-clamp: 2;这个属性不生效?
在项目中要实现多行省略,-webkit-line-clamp: 2;打包后不生效,使用下面的方法: word-break: break-all; text-overflow: ellipsis; di ...
- css之relative
一.relative对absolute的限制作用 1.限制left/top/right/bottom定位.absolute默认是在也没的左上角,当父类设定为relative,absolute就被限制在 ...
- LeetCode(102):二叉树的层次遍历
Medium! 题目描述: 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 ...
- 【python】spark+kafka使用
网上用python写spark+kafka的资料好少啊 自己记录一点踩到的坑~ spark+kafka介绍的官方网址:http://spark.apache.org/docs/latest/strea ...
- Python内置模块之序列化模块
序列化模块 json dumps loads dump load pickle dumps loads dump load shelve json 1: dumps/loads import json ...
- spring中的xml配置出处
- install memcached for ubuntu
Memcached安装 1.先下载安装libevent 安装 libevent# tar zxvf libevent-1.4.9-stable.tar.gz# cd libevent-1.4.9-st ...
- IDEA导入JAR的源代码
- .NetCore 下开发独立的(RPL)含有界面的组件包 (六)实现业务功能
.NetCore 下开发独立的(RPL)含有界面的组件包 (一)准备工作 .NetCore 下开发独立的(RPL)含有界面的组件包 (二)扩展中间件及服 务 .NetCore 下开发独立的(RPL)含 ...
- jQuery 核心 - noConflict() 方法[避免冲突的方法]
定义和用法 noConflict() 方法让渡变量 $ 的 jQuery 控制权. 语法 jQuery.noConflict([removeAll]) 参数描述removeAll布尔值.指示是否允许彻 ...