国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

MyBatis基于pagehelper實現分頁原理及代碼實例

瀏覽:97日期:2023-10-24 08:10:08

使用pagehelper分頁的原理是:

通過MyBatis的插件原理(類似web里的filter攔截器),在mapper配置文件將pagehelper注冊為MyBatis的插件,從而進行分頁

1.通過maven引入pagehelper依賴:

<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper --><dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.11</version></dependency>

2.在MyBatis的mapper配置文件將pagehelper注冊為MyBatis的插件

 <plugins> <plugin interceptor='com.github.pagehelper.PageInterceptor'></plugin> </plugins>

3.pagehelper的用法:

private void selectAllUsers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String num=request.getParameter('num'); if(null==num) { num='1'; } // Page PageInfo Page<?> page=PageHelper.startPage(Integer.parseInt(num),5); //設置第幾條記錄開始,多少條記錄為一頁 //通過userService獲取user的信息,其sql語句為'select * from user' 但因pagehelp已經注冊為插件,所以pagehelp會在原sql語句上增加limit,從而實現分頁 List<Person> persons=userService.getAllUsersBypageHelper(); //因而獲得的是分好頁的結果集 PageInfo<?> pageHelper=page.toPageInfo(); //獲取頁面信息的對象,里面封裝了許多頁面的信息 如:總條數,當前頁碼,需顯示的導航頁等等 request.setAttribute('persons',persons); request.setAttribute('pagehelper',pageHelper); request.getRequestDispatcher('/persons.jsp').forward(request,response); }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 河间市| 勐海县| 灵宝市| 永寿县| 阿鲁科尔沁旗| 永兴县| 垣曲县| 神木县| 加查县| 明溪县| 海伦市| 兴山县| 玛曲县| 墨玉县| 新巴尔虎左旗| 阿合奇县| 荣昌县| 五指山市| 上林县| 鄱阳县| 光泽县| 平顺县| 恭城| 和硕县| 滨州市| 德州市| 万安县| 申扎县| 新邵县| 陇西县| 明光市| 卢氏县| 丰宁| 东乡| 民权县| 沽源县| 永登县| 永福县| 临海市| 大渡口区| 海兴县|