zoukankan      html  css  js  c++  java
  • pageHelper使用。

    PageHelper简介
    PageHelper是Github上开源的MyBatis分页插件,使用起来非常的简单,方便,并且支持任何复杂的单表、多表分页。Github网址:
    
    https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md。
    

    使用maven引入相关的jar

    //分页插件包
    <dependency>
    	<groupId>com.github.pagehelper</groupId>
    	<artifactId>pagehelper-spring-boot-starter</artifactId>
    	<version>1.2.5</version>
    </dependency>
    //导入mybatis包
    <dependency>
    	<groupId>org.mybatis.spring.boot</groupId>
    	<artifactId>mybatis-spring-boot-starter</artifactId>
    	<version>1.3.2</version>
    </dependency>
    

    配置PageHelper

    #pagehelper 分页插件配置参数。
    pagehelper:
        helperDialect: mysql
        reasonable: true
        supportMethodsArguments: true
        params: count=countSql
        returnPageInfo: check
    
    使用pageHelper
        @Override
        public PageInfo<ContentDomain> searchArticle(String param, int pageNun, int pageSize) {
            PageHelper.startPage(pageNun,pageSize);
            List<ContentDomain> contentDomains = contentDao.searchArticle(param);
            PageInfo<ContentDomain> pageInfo = new PageInfo<>(contentDomains);
            return pageInfo;
        }
    /*
    PageHelper.startPage(pageNum, pageSize);
    pageNum:页数(第几页)
    pageSize:每页的数据行数
    这样就可以实现查询分页了。
    */
    

    分析PageInfo类种主要属性的用法

    	//当前页
        private int pageNum;
        //每页的数量
        private int pageSize;
        //当前页的数量
        private int size;
    
        //由于startRow和endRow不常用,这里说个具体的用法
        //可以在页面中"显示startRow到endRow 共size条数据"
    
        //当前页面第一个元素在数据库中的行号
        private int startRow;
        //当前页面最后一个元素在数据库中的行号
        private int endRow;
        //总页数
        private int pages;
    
        //前一页
        private int prePage;
        //下一页
        private int nextPage;
    
        //是否为第一页
        private boolean isFirstPage = false;
        //是否为最后一页
        private boolean isLastPage = false;
        //是否有前一页
        private boolean hasPreviousPage = false;
        //是否有下一页
        private boolean hasNextPage = false;
        //导航页码数
        private int navigatePages;
        //所有导航页号
        private int[] navigatepageNums;
        //导航条上的第一页
        private int navigateFirstPage;
        //导航条上的最后一页
        private int navigateLastPage;
    
    努力学习java的Cherish
  • 相关阅读:
    CFS 调度器
    RCU
    linux cfs 负载均衡
    wait_event_interruptible_timeout
    算法(13)Contiguous Array
    算法(12)Pascal's Triangle II
    算法(12)Best Time to Buy and Sell Stock II
    算法(11)Find All Duplicates in an Array
    算法(10)Subarray Sum Equals K
    算法(9)Find the Duplicate Number
  • 原文地址:https://www.cnblogs.com/cherish-code/p/14110112.html
Copyright © 2011-2022 走看看