博客
关于我
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 Binlog 日志监听与 Spring 集成实战
    查看>>
    multi-angle cosine and sines
    查看>>
    Mysql Can't connect to MySQL server
    查看>>
    mysql case when 乱码_Mysql CASE WHEN 用法
    查看>>
    Multicast1
    查看>>
    MySQL Cluster 7.0.36 发布
    查看>>
    Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
    查看>>
    multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
    查看>>
    mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
    查看>>
    Multiple websites on single instance of IIS
    查看>>
    mysql CONCAT()函数拼接有NULL
    查看>>
    multiprocessing.Manager 嵌套共享对象不适用于队列
    查看>>
    multiprocessing.pool.map 和带有两个参数的函数
    查看>>
    MYSQL CONCAT函数
    查看>>
    multiprocessing.Pool:map_async 和 imap 有什么区别?
    查看>>
    MySQL Connector/Net 句柄泄露
    查看>>
    multiprocessor(中)
    查看>>
    mysql CPU使用率过高的一次处理经历
    查看>>
    Multisim中555定时器使用技巧
    查看>>
    MySQL CRUD 数据表基础操作实战
    查看>>