If we have a mapped statement that returns multiple rows and we want the results in a HashMap with some property value as the key and the resulting object as the value, we can use sqlSession.selectMap() as follows:

<select id=" findAllStudents" resultMap="StudentResult">
select * from Students
</select> Map<Integer, Student> studentMap = sqlSession.selectMap("com.mybatis3.mappers.StudentMapper.findAllStudents", "studId");

Here studentMap will contain studId values as keys and Student objects as values.

MyBatis(3.2.3) - Multiple results as a map的更多相关文章

  1. MyBatis传入参数为list、数组、map写法(转载)

    MyBatis传入参数为list.数组.map写法 1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item ...

  2. MyBatis传入参数为list、数组、map写法

    1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item,index,collection,open,sep ...

  3. A Tour of Go Multiple results

    A function can return any number of results. This function returns two strings. package main import ...

  4. MyBatis的一系列问题的处理(遍历Map集合和智能标签和属性和字段不一样的解决办法 和sql片段)(三)

    一.字段名与属性名(数据库的名字)不一样怎么办? 方案一:在小配置中配置一个resultMapper <!--方案一:resultMapper 字段名与属性名不一致 --> <res ...

  5. 使用MyBatis时接收值和返回值选择Map类型或者实体类型

    MyBatis作为现近JavaEE企业级项目开发中常用的持久层框架之一,以其简洁高效的ORM映射和高度的SQL的自由性被广大开发人员认可.Mybatis在接收系统传来的参数和返回的参数时主要可以有Ma ...

  6. mybatis框架之多参数入参--传入Map集合

    需求:查询出指定性别和用户角色列表下的用户列表信息 实际上:mybatis在入参的时候,都是将参数封装成为map集合进行入参的,不管你是单参数入参,还是多参数入参,都是可以封装成map集合的,这是无可 ...

  7. Mybatis之foreach用法----List、Array、Map三种类型遍历

    在mybatis的xml文件中构建动态sql语句时,经常会用到标签遍历查询条件.特此记录下不同情况下书写方式!-------仅供大家参考------ 1. foreach元素的属性 collectio ...

  8. MyBatis的foreach语句详解 list array map

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的属性主要有 item,index,collection,open,separator,close.it ...

  9. Table of Contents - MyBatis

    Getting Started with MyBatis Hello World Integration with Spring Bootstrapping MyBatis Configuring M ...

随机推荐

  1. windows服务控制类

    /// <summary> /// 服务调用控制 /// </summary> public class WinServiceController { /// <summ ...

  2. Flash Builder 4.6 界面显示一半中文一半英文?

    Flash Builder 4.6 (简称 Flex 4.6 或 FB 4.6)启动后界面有时候会显示一半中文,一半英文(这种奇葩的情况一般发生在 FB 4.6 刚安装后或操作系统安装一个类似 SP1 ...

  3. 小菜学习MVC4-WebApi

    今天想看下MVC4的东西,发现 居然有WebApi这东西,百度了一下..居然是 WCF中的东西,然后移植到了MVC4中,WCF你懂得返回数据都是xml,向网站这种请求 就比较纠结...而webapi可 ...

  4. 使用CKEditor编辑器进行文本编辑

    首先下载CKEditor. 下载地址:点击打开链接 将下载完的CKEditor解压而且导入到项目中. 然后在页面引入CKEditor <script type="text/javasc ...

  5. key 限制字符的输入

    //限制字符的输入 { 只能输入以下字符 } procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);begin  If (Key ...

  6. Linux守护进程(init.d和xinetd)

    http://www.cnblogs.com/itech/archive/2010/12/27/1914846.html

  7. python 学习(一)

    python的基础看完了之后,有点像简化并提供了一定优化后的java基础,看java多了的人看python还是比较别扭的.看完别人对于java和python的对比,我只能感慨一句,还有什么是java办 ...

  8. MySQL_前缀索引_建立

    -- 查看出现频率select count(*) as cnt,cityfrom sakila.city_demo group by city order by cnt desc limit 10; ...

  9. 如何获取input自定义属性

    javascript方法: <input type="checkbox"  name="sdf"  data="这是自定义属性" /& ...

  10. BootStrap2学习日记13----关于按钮

    普通按钮 代码: <div style="margin-bottom:15px"> <a href="#" class="" ...