zoukankan      html  css  js  c++  java
  • 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());
              }
          }
  • 相关阅读:
    Dropplets – 极简的 Markdown 博客平台
    T3
    Awesomplete
    SVG Drawing Animation
    Dom Animator – 提供 Dom 注释动画的 JS 库
    Electron
    很赞的效果!互动的页面元素拖放着色实验
    BookBlock
    雷军投资的理财网站,年化收益13%!
    Rainyday.js – 使用 JavaScript 实现雨滴效果
  • 原文地址:https://www.cnblogs.com/forever2h/p/6795981.html
Copyright © 2011-2022 走看看