pageHelper分頁外掛實現原理及使用方法
阿新 • • 發佈:2018-12-23
外掛官方網站:https://github.com/pagehelper/Mybatis-PageHelper/tree/master/src/main/java/com/github/pagehelper
實現原理:
使用方法:
第一步:引入pageHelper的jar包。
第二步:需要在SqlMapConfig.xml中配置外掛。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 配置分頁外掛 --> <plugins> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 設定資料庫型別 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種資料庫--> <property name="dialect" value="mysql"/> </plugin> </plugins> </configuration>
第三步:在查詢的sql語句執行之前,新增一行程式碼:
PageHelper.startPage(1, 10);
第一個引數是page,要顯示第幾頁。
第二個引數是rows,沒頁顯示的記錄數。
第四步:取查詢結果的總數量。
建立一個PageInfo類的物件,從物件中取分頁資訊。