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

最新文章

  1. smartroute简单集成集群聊天通讯
  2. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告
  3. 通过cpu SN码注册软件类
  4. 《Cocos2d-x实战 JS卷 Cocos2d-JS开发》上线了
  5. java io文件学习笔记
  6. thinkphp基础入门(1)
  7. 与众不同 windows phone (7) - Local Database(本地数据库)
  8. JS阻塞以及CSS阻塞
  9. nginx的5个特点
  10. AIO5打印样式函数说明
  11. [ Java学习基础 ] String、StringBuffer、StringBuilder比较学习
  12. Python2 与 Python3 的编码对比
  13. 金蝶KIS&amp;K3助记码SQL数据库批量刷新
  14. zepto 事件分析3(add函数)
  15. HDU 5033
  16. dubbo学习汇总
  17. MySql:SELECT 语句(一)基本查询
  18. 服务器运维 -- windows系统更换System32下文件后 重启无法进入桌面
  19. MySQL之慢查询日志分析
  20. Eclipse实现数据库反向生成实体类(pojo)-------(插件安装和实现步骤的说明)

热门文章

  1. Laravel 5.2 错误-----ReflectionException in compiled.php line 8572: Class App\Http\Controllers\Apih5\ZhaoshangController does not exist
  2. ubuntu 安装配置 mysql
  3. sudo初级授权设置
  4. 29)django-ORM连表结构
  5. 处理:&ldquo;ORA-00257: archiver error. Connect internal only, until freed&rdquo;的错误问题
  6. nginx常用命令及简单配置
  7. exec与match方法的区别
  8. php实现备份数据库
  9. BrupSuite渗透测试笔记(十一)
  10. django----Form实时更新两种方式