分頁插件pagehelper

mybatis-pagehelper

  1. 引入分頁插件
        <!--pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.12</version>
        </dependency>
  1. 配置yml
# 分頁插件配置
pagehelper:
  helperDialect: mysql
  supportMethodsArguments: true
  1. 使用分頁插件,在查詢前使用分頁插件,原理:統(tǒng)一攔截sql,為其提供分頁功能
PageHelper.startPage(pageNum,pageSIze);
  1. 分頁數(shù)據(jù)封張到PagedGridresult.java傳給前端
PageInfo<?> pageList = new PageInfo(list);
PagedGridresult grid = new PagedGridResult();
grid.setPage(page);
grid.setRows(list);
grid.setTotal(pageList.getPages());
grid.setRecords(pageList.getTotal());

PagedGridResult類

public class PagedGridResult {
    
    private int page;           // 當(dāng)前頁數(shù)
    private int total;          // 總頁數(shù)  
    private long records;       // 總記錄數(shù)
    private List<?> rows;       // 每行顯示的內(nèi)容

    public int getPage() {
        return page;
    }
    public void setPage(int page) {
        this.page = page;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    public long getRecords() {
        return records;
    }
    public void setRecords(long records) {
        this.records = records;
    }
    public List<?> getRows() {
        return rows;
    }
    public void setRows(List<?> rows) {
        this.rows = rows;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容