• mybatis 之 mybatis中查询


    1. Mybatis 中又3种查询 seleteOne, seleteList, seleteMap.
    2. SeleteOne 查询单个对象:

      映射文件:

      <!-- 根据id查询 -->
          <select id="findById" parameterType="int" resultType="cn.wh.vo.Role">
              select * from t_role where id = #{id}
          </select>
          <select id="totalCount" resultType="int">
              select count(*) from t_role
          </select>

      测试

      //查询单个
          @Test
          public void testSelectOne(){
              Role role = (Role)session.selectOne("cn.wh.mapper.RoleMapper.findById",1);
              System.out.println(role.getName());
          }
          //查询count
          @Test
          public void testSelectCount(){
              Integer count = (Integer)session.selectOne("cn.wh.mapper.RoleMapper.totalCount");
              System.out.println(count);
          }
    3. selectList  查询结果集:
      //查询所有
          @Test
          public void testSelectList(){
              List<Role> list = session.selectList("cn.wh.mapper.RoleMapper.findAll");
              for(Role role:list){
                  System.out.println(role.getId()+"----"+role.getName());
              }
          }
    4. selectMap 查询Map集合:
      @Test
          public void testSelectMap(){
              //第二参数是列名  作为 map的key
              Map<Integer,Role> map = session.selectMap("cn.wh.mapper.RoleMapper.findAll", "id");
              Iterator<Integer> iter = map.keySet().iterator();
              while(iter.hasNext()){
                  Integer key = iter.next();
                  System.out.println(key+"--------"+map.get(key).getName());
              }
          }
  • 相关阅读:
    分布式事务之可靠消息
    分布式事务之本地消息表
    分布式事务
    数据库之 事务
    WePY开发小程序(二):项目入口及注册页面、组件
    WePY开发小程序(一):入门
    vue学习笔记-事件监听
    vue学习笔记-列表渲染
    vue学习笔记-缩写
    vue学习笔记-常用指令
  • 原文地址:https://www.cnblogs.com/forever2h/p/6795981.html
Copyright © 2020-2023  润新知