mybatis官方学习文档:http://www.mybatis.org/core/getting-started.html

本文转自:http://www.blogjava.net/xmatthew/archive/2011/08/31/355879.html

1. 当查询的参数只有一个时 
  findByIds(List<Long> ids)
 1.1 如果参数的类型是List, 则在使用时,collection属性要必须指定为 list

  1. <select id="findByIdsMap" resultMap="BaseResultMap">
  2. Select
  3. <include refid="Base_Column_List" />
  4. from jria where ID in
  5. <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
  6. #{item}
  7. </foreach>
  8. </select>

findByIds(Long[] ids)
 1.2 如果参数的类型是Array,则在使用时,collection属性要必须指定为 array

  1. <select id="findByIdsMap" resultMap="BaseResultMap">
  2. select
  3. <include refid="Base_Column_List" />
  4. from tabs where ID in
  5. <foreach item="item" index="index" collection="array" open="(" separator="," close=")">
  6. #{item}
  7. </foreach>
  8. </select>

2. 当查询的参数有多个时,例如 findByIds(String name, Long[] ids)
 这种情况需要特别注意,在传参数时,一定要改用Map方式, 这样在collection属性可以指定名称
         下面是一个示例
         Map<String, Object> params = new HashMap<String, Object>(2);
         params.put("name", name);
         params.put("ids", ids);
        mapper.findByIdsMap(params);

  1. <select id="findByIdsMap" resultMap="BaseResultMap">
  2. select
  3. <include refid="Base_Column_List" />
  4. from tabs where ID in
  5. <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
  6. #{item}
  7. </foreach>
  8. </select>

mybatis sql in 查询的更多相关文章

  1. Mybatis SQL语句查询

    MyBatis中使用in查询时的注意事项 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach一共有三种类型,分别为List,[](array),Map三种. ...

  2. mybatis sql in 查询(mybatis sql语句传入参数是list)mybatis中使用in查询时in怎么接收值

    1.in查询条件是list时 <select id="getMultiMomentsCommentsCounts" resultType="int"> ...

  3. 8.mybatis动态SQL模糊查询 (多参数查询,使用parameterType)

    多参数查询,使用parameterType.实例: 用户User[id, name, age] 1.mysql建表并插入数据 2.Java实体类 public class User { public ...

  4. Mybatis之关联查询及动态SQL

    前言 实际开发项目中,很少是针对单表操作,基本都会联查多表进行操作,尤其是出一些报表的内容.此时,就可以使用Mybatis的关联查询还有动态SQL.前几篇文章已经介绍过了怎么调用及相关内容,因此这里只 ...

  5. mybatis的sql参数化查询

    我们使用jdbc操作数据库的时候,都习惯性地使用参数化的sql与数据库交互.因为参数化的sql有两大有点,其一,防止sql注入:其二,提高sql的执行性能(同一个connection共用一个的sql编 ...

  6. mybatis中的查询缓存

    一: 查询缓存 Mybatis提供查询缓存,用于减轻数据压力,提高数据库压力. Mybatis提供一级缓存和二级缓存. 在操作数据库时需要构造SqlSession对象,在对象中有一个数据结构(Hash ...

  7. 【Mybatis框架】查询缓存(二级缓存)

    继上一篇博客,我们讲述了mybatis的一级缓存,接下来,我们来学习一下mybatis的二级缓存 博客链接地址: http://blog.csdn.NET/liweizhong193516/artic ...

  8. Mybatis之关联查询

    一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 创建一张教师表和班级表,这里我们假设一个老师只负责教一个班,那么老师和班级之间的关系就是一种一对一的关 ...

  9. Mybatis多条件查询

    在Mybatis多条件查询中: 1.参数如果是多条件,则需要将将添加到Map集合中进行传入. 2.就是将其参数用有序数字进行代替. Mybatis单个String类型参数传递 mysql文如下,传入参 ...

随机推荐

  1. MFC通过ODBC方式连接mysql

    一. 要安装mysql-connector-odbc驱动 二. 配置数据源 电脑的控制面板-管理工具-数据源ODBC-系统DSN-添加-选择刚刚安装的mysql odbc Driver 参考 http ...

  2. 面试题-链表反转c实现

    // ListReverse.cpp : Defines the entry point for the console application.// #include "stdafx.h& ...

  3. CentOS 6.4下编译安装 gcc-4.8.0(转)

    转:http://www.centoscn.com/image-text/install/2014/0807/3454.html 1.首先下载源代码 wget http://ftp.gnu.org/g ...

  4. URL、URI和URN三者之间的区别

    URI   统一资源标识符 Uniform Resource Identifier URL      统一资源定位符     Uniform Resource Locator URN     统一资源 ...

  5. 常用HTML正则表达式

    1.只能输入数字和英文的: <input onkeyup="value=value.replace(/[\W]/g,'') " > 2.只能输入数字的: <inp ...

  6. Robotlegs框架1.5简介

    该框架的1.5版本位于https://github.com/robotlegs/robotlegs-framework/tree/version1,现在已经出了重新架构的2.0版本,所以我决定先研究已 ...

  7. noi 4978 宠物小精灵之收服

    题目链接:http://noi.openjudge.cn/ch0206/4978/ 二维费用背包 在最后找还剩多少体力的时候,直接找到第二维,当结果 f[n][i] == f[n][m] 时,就说明已 ...

  8. selenium操作滚动条方法

    /***  滚动条滚到最下方,和滚到指定位置*/@Test(priority =1 )    public void scrollingToBottomo(){        //使用JavaScri ...

  9. background-clip 制作文字火焰效果

    1.Background-clip的语法 background-clip: border-box || padding-box || context-box || no-clip || text 2. ...

  10. 在代码中调用gdb

    转载:http://blog.csdn.net/hanchaoman/article/details/5583457 在SIGSEGV的handler中调用gdb, 命令gdb [exec file] ...