博客
关于我
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/

    你可能感兴趣的文章
    Openlayers实战:绘制图形,导出KML文件
    查看>>
    Openlayers实战:绘制多边形,导出CSV文件
    查看>>
    Openlayers实战:绘制带箭头的线
    查看>>
    Openlayers实战:绘制点、线、圆、多边形
    查看>>
    Openlayers实战:绘制矩形,正方形,正六边形
    查看>>
    Openlayers实战:自定义放大缩小,显示zoom等级
    查看>>
    Openlayers实战:自定义版权属性信息
    查看>>
    Openlayers实战:输入WKT数据,输出GML、Polyline、GeoJSON格式数据
    查看>>
    Openlayers实战:选择feature,列表滑动,定位到相应的列表位置
    查看>>
    Openlayers实战:非4326,3857的投影
    查看>>
    Openlayers高级交互(1/20): 控制功能综合展示(版权、坐标显示、放缩、比例尺、测量等)
    查看>>
    Openlayers高级交互(10/20):绘制矩形,截取对应部分的地图并保存
    查看>>
    Openlayers高级交互(11/20):显示带箭头的线段轨迹,箭头居中
    查看>>
    Openlayers高级交互(12/20):利用高德逆地理编码,点击位置,显示坐标和地址
    查看>>
    Openlayers高级交互(13/20):选择左右两部分的地图内容,横向卷帘
    查看>>
    Openlayers高级交互(14/20):汽车移动轨迹动画(开始、暂停、结束)
    查看>>
    Openlayers高级交互(15/20):显示海量多边形,10ms加载完成
    查看>>
    Openlayers高级交互(16/20):两个多边形的交集、差集、并集处理
    查看>>
    Openlayers高级交互(17/20):通过坐标显示多边形,计算出最大幅宽
    查看>>
    Openlayers高级交互(18/20):根据feature,将图形适配到最可视化窗口
    查看>>