久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      mybatis分頁的幾種方式是什么

      mybatis分頁的3種方式是:1、使用Limit分頁,其核心語句如“select * from users limit startIndex,pageSize;”;2、使用RowBounds實(shí)現(xiàn)分頁,語句如“ListgetUserLRowBounds();”;3、使用分頁插件“PageHelper”實(shí)現(xiàn)即可。

      mybatis分頁的幾種方式是什么

      本教程操作環(huán)境:Windows10系統(tǒng)、Dell G3電腦。

      mybatis分頁的幾種方式是什么?

      MyBatis常用的幾種分頁方式

      為什么要分頁?

      如果前端需要展示數(shù)據(jù)時(shí),由于數(shù)據(jù)量龐大,一次性展示,這時(shí)頁面將會(huì)出現(xiàn)一大片數(shù)據(jù),而且還不一定加載完成,效率很差,此時(shí)分頁查詢就可以很好的解決這一問題,將龐大的數(shù)據(jù)按照一定數(shù)目顯示出,還可以通過點(diǎn)擊下一頁或者上一頁展示其它數(shù)據(jù),效率更高!

      下面來介紹下mybatis常用的幾種分頁查詢!
      首先看一下數(shù)據(jù)庫里所有的數(shù)據(jù),細(xì)節(jié)代碼里有注解

      mybatis分頁的幾種方式是什么

      1、使用Limit分頁

      sql使用的核心語句
      登錄后復(fù)制

      -- 語法:表示從startIndex下標(biāo)開始,一頁顯示pageSize個(gè) select * from users limit startIndex,pageSize; -- 語法:表示顯示[0,n]范圍的數(shù)據(jù) select * from users limit n;
      登錄后復(fù)制

      使用Mybatis實(shí)現(xiàn)分頁,基于sql實(shí)現(xiàn)

      編寫接口

       //分頁查詢     List<User> getUserLImit(Map<String,Object> map);
      登錄后復(fù)制

      編寫Mapper.xml

      <!--    分頁查詢-->     <select id="getUserLImit" parameterType="map" resultType="pojo.User">         select * from firend_mq.users limit #{startIndex},#{pageSize}    </select>
      登錄后復(fù)制

      測試類

          //測試分頁查詢     @Test     public  void getUserLImit(){         SqlSession sqlSession = Mybatisutil.getSqlSession();         UserDao mapper = sqlSession.getMapper(UserDao.class);          Map<String, Object> map = new HashMap<>();         map.put("startIndex",0);         map.put("pageSize",3);         List<User> userLImit = mapper.getUserLImit(map);         for (User user : userLImit) {             System.out.println(user);         }         sqlSession.close();     }
      登錄后復(fù)制

      查詢結(jié)果:

      mybatis分頁的幾種方式是什么

      2、RowBounds實(shí)現(xiàn)分頁

      基于RowBounds類對(duì)象實(shí)現(xiàn),基于java代碼

      編寫接口

      //RowBounds實(shí)現(xiàn)分頁查詢     List<User> getUserLRowBounds();
      登錄后復(fù)制

      編寫Mapper.xml,查詢的其實(shí)是全部用戶

         <!--   RowBounds 分頁查詢-->     <select id="getUserLRowBounds"  resultType="pojo.User">         select * from firend_mq.users    </select>
      登錄后復(fù)制

      測試類

          //RowBounds分頁查詢     @Test     public  void getUserLRowBounds(){         SqlSession sqlSession = Mybatisutil.getSqlSession();         //RowBounds對(duì)象  參數(shù)(起點(diǎn),個(gè)數(shù))         RowBounds rowBounds = new RowBounds(2, 3);          //通過java代碼層面實(shí)現(xiàn)分頁,第一個(gè)參數(shù)是接口類的方法路徑         List<User> userlist = sqlSession.selectList("dao.UserDao.getUserLRowBounds", null, rowBounds);         for (User user : userlist) {             System.out.println(user);         }         sqlSession.close();     }
      登錄后復(fù)制

      結(jié)果:

      mybatis分頁的幾種方式是什么

      3、使用分頁插件實(shí)現(xiàn)

      mybatis分頁的幾種方式是什么

      感興趣的可以了解下,放個(gè)該插件的官網(wǎng)鏈接,有官方使用文檔,自行了解PageHelper分頁插件

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)