zoukankan      html  css  js  c++  java
  • 07 MyBatis——三种查询方式以及返回类型

    三种查询方式

    在使用SQLSession调用查询方式时,有三种查询方式

    1.selectList(方法) 返回值为List<ResultType 属性控制>

    2.selectOne(方法) 返回一个Object,适用于返回结果只是变量或一行数据时

    3.selectMap(方法,列名)  以列名为key,以列名所在的行的对象为value存入map中,如:

    Map<Object, Object> map = session.selectMap("cn.xiaohei.mapper.FlowerMapper.selAll", "name");
    

     

    selectMap中的两个参数分别为:

    • 调用Mapper中的查询方法selAll
    • 以name列的值为key

    表中数据如:

     查询结果如(Flower为实体对象):

    {矮牵牛=Flower [id=1, name=矮牵牛, price=2.5, production=南美阿根廷], 的=Flower [id=5, name=的, price=33.0, production=天庭], 王母娘娘=Flower [id=6, name=王母娘娘, price=33.0, production=], 半枝莲=Flower [id=3, name=半枝莲, price=4.3, production=巴西], 百日草=Flower [id=2, name=百日草, price=5.0, production=墨西哥], ???????¨??¨?=Flower [id=4, name=???????¨??¨?, price=23.0, production=?¤????]}

    返回类型

    在Mapper中,resultType这一项的返回值可选如下(左列):

  • 相关阅读:
    firefox安装教程
    shell脚本介绍
    vue 图片引入
    vscode 常用插件
    vscode 打不开chrome浏览器解决方案
    win10 wifi 密码查看
    爽文 主角如 石昊 白小纯 方行 秦牧 楚风
    codepen, jsrun 使用iframe嵌入
    uniapp 自定义扫一扫页面
    数组(遍历删除多个元素)
  • 原文地址:https://www.cnblogs.com/Scorpicat/p/12408030.html
Copyright © 2011-2022 走看看