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 多种传参方式的更多相关文章

  1. PHP四种传参方式

    test1界面: <html> <head> <title>testPHP</title> <meta http-equiv = "co ...

  2. python 计算机发展史,线程Process使用 for循环创建 2种传参方式 jion方法 __main__的解释

    ########################总结################## #一 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬 ...

  3. Vue中router两种传参方式

    Vue中router两种传参方式 1.Vue中router使用query传参 相关Html: <!DOCTYPE html> <html lang="en"> ...

  4. axios的各种传参方式

    axios的各种传参方式 1. params方式 axios({ url: '/users', method: 'get', params: { id: '11111', name: '22222' ...

  5. vue param和query两种传参方式

    1.传参方式 query传参方式 this.$router.push({ path: "/home", query: {code:"123"} }) param ...

  6. 浅谈C++三种传参方式

    浅谈C++三种传参方式 C++给函数传参中,主要有三种方式:分别是值传递.指针传递和引用传递. 下面通过讲解和实例来说明三种方式的区别. 值传递 我们都知道,在函数定义括号中的参数是形参,是给函数内专 ...

  7. Mybatis的几种传参方式,你了解吗?

    持续原创输出,点击上方蓝字关注我 目录 前言 单个参数 多个参数 使用索引[不推荐] 使用@Param 使用Map POJO[推荐] List传参 数组传参 总结 前言 前几天恰好面试一个应届生,问了 ...

  8. vector作为参数的三种传参方式

    c++中常用的vector容器作为参数时,有三种传参方式,分别如下(为说明问题,用二维vector): function1(std::vector<std::vector<int> ...

  9. vue的三种传参方式

    <template> <div> <router-link :to="{'name':'x',params:{'type':'users'}}"> ...

随机推荐

  1. JetBrains GoLand 2018 激活码/ 注册码(最新破解方法)

    1 前言 本机测试环境如下: Goland版本:2018.1.5 电脑系统:win7 64位 JetbrainsCrack.jar:链接: https://pan.baidu.com/s/1blmN3 ...

  2. ( linker command failed with exit code 1) 错误解决方案 项目使用的是pod

    targets -> build settings -> architectures -> build active architecture only -> debug 改成 ...

  3. canvas 保存bitmap到本地

    File f = new File("/sdcard/DCIM/Camera/0.png"); FileOutputStream fos = null; try { fos = n ...

  4. vuejs项目---配置理解:

    当我们需要和后台分离部署的时候,必须配置config/index.js: 用vue-cli 自动构建的目录里面  (环境变量及其基本变量的配置) 1 2 3 4 5 6 7 8 9 10 11 12 ...

  5. 《剑指offer》顺时针打印矩阵

    本题来自<剑指offer> 顺时针打印矩阵 题目: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 1 ...

  6. ubuntu18.04进不了桌面

    ubuntu升级18.04进不了桌面 https://chengfeng.site/2018/05/02/ubuntu%E5%8D%87%E7%BA%A718-04%E8%B8%A9%E7%9A%84 ...

  7. bzoj 1222

    比较简单的背包dp,设计状态f[i][j]表示到了前i个物品,第一台机器加工时间为j,第二台机器加工所用的最小时间,然后背包转移即可 本题卡空间,需要滚动数组优化 本题卡时间,稍微卡下常就行 #inc ...

  8. IP的计算

    IP的计算 时间限制: 1 Sec  内存限制: 32 MB 位无符号整数来表示,一般用点分方式来显示,点将IP地址分成4个部分,每个部分为8位,表示成一个无符号整数(因此不需要用正号出现),如192 ...

  9. web.xml中的ContextLoaderListener和DispatcherServlet区别

    ContextLoaderListener和DispatcherServlet都会在Web容器启动的时候加载一下bean配置. 区别在于: DispatcherServlet一般会加载MVC相关的be ...

  10. 一个简单的binlog恢复测试

    日常的数据备份及恢复测试,是DBA工作重中之重的事情,所以要做好备份及测试,日常的备份常见有mysqldump+binlog备份.xtrabackup+binlog备份,无论那一种,几乎都少不了对bi ...