博客
关于我
06 sql映射之返回值类型(resultType)
阅读量:232 次
发布时间:2019-03-01

本文共 1439 字,大约阅读时间需要 4 分钟。

文章目录

resultType属性就是指定返回值类型,这一章节主要介绍resultType属性

1 返回集合

如果返回值是一个集合,resultType并非指定为集合类型,而是指定为集合内元素的类型

比如:

List         selectAll();
select       *   from       tb_user

测试:

@Testpublic void test01() {       List         list = tbUserMapper.selectAll();    System.out.println(list);}

2 返回Map

  • key就是列名,value就是对应的数据,resultType指定为map
  • 比如:

    Map         selectById(@Param("id") Long id);
    select        *    from        tb_user    where        id = #{id}

    测试:

    @Testpublic void test02() {       Map         map = tbUserMapper.selectById(1L);    System.out.println(map);}

    输出结果:

    {   password=123456, update_time=2019-04-04 22:58:26.0, create_time=2019-04-04 22:58:26.0, phone=13100001111, id=1, username=kobe}
    1. 返回的map,key是主键,value是这个主键对应的数据呢
      • resultType指定为map
      • 在mapper接口中使用@MapKey注解指定,返回map的key
    2. @MapKey("id")Map         selectMap();
      select       *   from       tb_user

      测试:

      @Testpublic void test03() {       Map         map = tbUserMapper.selectMap();    for (Long id : map.keySet()) {           System.out.println(id + "--->" + map.get(id));    }}

      输出:

      1--->{   password=123456, update_time=2019-04-04 22:58:26.0, create_time=2019-04-04 22:58:26.0, phone=13100001111, id=1, username=kobe}5--->{   password=123456, update_time=2021-01-31 11:44:22.0, create_time=2021-01-31 11:44:22.0, phone=13011112222, id=5, username=t-mac}6--->{   password=123456, update_time=2021-01-31 11:44:56.0, create_time=2021-01-31 11:44:56.0, phone=13011112222, id=6, username=t-mac}

    转载地址:http://wsrv.baihongyu.com/

    你可能感兴趣的文章
    mysql中的undo log、redo log 、binlog大致概要
    查看>>
    Mysql中的using
    查看>>
    MySQL中的关键字深入比较:UNION vs UNION ALL
    查看>>
    mysql中的四大运算符种类汇总20多项,用了三天三夜来整理的,还不赶快收藏
    查看>>
    mysql中的字段如何选择合适的数据类型呢?
    查看>>
    MySQL中的字符集陷阱:为何避免使用UTF-8
    查看>>
    mysql中的数据导入与导出
    查看>>
    MySQL中的时间函数
    查看>>
    mysql中的约束
    查看>>
    MySQL中的表是什么?
    查看>>
    mysql中穿件函数时候delimiter的用法
    查看>>
    Mysql中索引的分类、增删改查与存储引擎对应关系
    查看>>
    Mysql中索引的最左前缀原则图文剖析(全)
    查看>>
    MySql中给视图添加注释怎么添加_默认不支持_可以这样取巧---MySql工作笔记002
    查看>>
    Mysql中获取所有表名以及表名带时间字符串使用BetweenAnd筛选区间范围
    查看>>
    Mysql中视图的使用以及常见运算符的使用示例和优先级
    查看>>
    Mysql中触发器的使用示例
    查看>>
    Mysql中设置只允许指定ip能连接访问(可视化工具的方式)
    查看>>
    mysql中还有窗口函数?这是什么东西?
    查看>>
    mysql中间件
    查看>>