JSON and pageinfo

Stella981
• 阅读 393

    中国

   

        黑龙江

    

            哈尔滨

            大庆

       

   

   

        广东

       

            广州

            深圳

            珠海

       

   

用JSON表示如下:

{

{name:"中国", province:[ { name:"黑龙江", cities:{ city:["哈尔滨","大庆"] },

{name:"广东", cities:{ city:["广州","深圳","珠海"] } 

}

package  +  ****

/**
 * 分页的工具类
 *
 */
public class PageInfoUtil
{
    /* 总条数 */
    private int totalRecord;
    /* 每页多少条 */
    private int pageSize = 10;

    /* 总页数 */
    private int totalPage;
    /* 当前页 */
    private int currentPage;
    /* 上一页 */
    private int prePage;
    /* 下一页 */
    private int nextPage;

    /*
     * 当前页对应的条数 如果每页10条, 1 1 2 11 3 21
     * 
     * limit ?(currRecord),?(pageSize)
     */
    private int currRecord;

    public int getTotalRecord()
    {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord)
    {
        this.totalRecord = totalRecord;
    }

    public int getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }

    public int getCurrentPage()
    {
        /*
         * -1,
         * 100000>总页数的时候
         * 获取当前页的时候要做一个判断
         * */
        if(this.currentPage < 1)
        {
            this.currentPage = 1 ; 
        }
        if(this.getTotalPage() > 0 && this.currentPage > this.getTotalPage())
        {
            this.currentPage = this.getTotalPage() ; 
        }
        return currentPage;
    }

    public void setCurrentPage(int currentPage)
    {
        this.currentPage = currentPage;
    }

    public int getTotalPage()
    {
        /*
         * 总页数
         * 总记录数:每页多少条,
         * 总页数????咋算?
         * 
         * 总记录数,每页多少条
         * 21        10        3
         * 20        10         2
         * */
        if(this.totalRecord % this.pageSize == 0)
        {
            this.totalPage = this.totalRecord / this.pageSize; 
        }else
        {
            this.totalPage = this.totalRecord / this.pageSize + 1;
        }
        return totalPage;
    }

    public int getPrePage()
    {
        this.prePage = this.getCurrentPage() - 1 ;
        /*
         * 总页数为:5
         * this.getCurrentPage():的值:1 --- > 5
         * 上页一页的值:0-->4
         * 所以上一页的取值范围木有必须和总页数相比,因为上一页始终小于总页数
         * */
        if(this.prePage < 1)
        {
            this.prePage = 1 ; 
        }
        return prePage;
    }

    public int getNextPage()
    {
        this.nextPage = this.getCurrentPage() + 1 ;
        /*
         * 总页数为:5
         * this.getCurrentPage():的值:1 --- > 5
         * 下一页的值:2-->6
         * 所以上一页的取值范围木有必须和总页数相比,因为上一页始终小于总页数
         * */
        if(this.getTotalPage() > 0 && this.nextPage > this.getTotalPage())
        {
            this.nextPage = this.getTotalPage() ; 
        }
        return nextPage;
    }

    public int getCurrRecord()
    {
        /*
         *当前页的条数:
         * 每页10条
         * 当前页    当前页的条数
         * 1        1
         * 2        11
         * 3        21
         * 4        31
         * 5        51
         * 数据库的索引值是从0开始的
         * SELECT * FROM `a_admins` LIMIT 0, 1000
         * 因为数据库的原因,不应该+1
         */
        this.currRecord = (this.getCurrentPage() - 1 ) * this.pageSize; 
        return currRecord;
    }
    
    public static void main(String[] args)
    {
        PageInfoUtil pageInfoUtil = new PageInfoUtil() ; 
        pageInfoUtil.setTotalRecord(50);
        pageInfoUtil.setPageSize(10);
        pageInfoUtil.setCurrentPage(1000);
        System.out.println(pageInfoUtil);
    }

    @Override
    public String toString()
    {
        return "PageInfoUtil [totalRecord=" + this.getTotalRecord() + ", pageSize=" + this.getPageSize() + ", totalPage=" + this.getTotalPage()
                + ", currentPage=" + this.getCurrentPage() + ", prePage=" + this.getPrePage() + ", nextPage=" + this.getNextPage() + ", currRecord="
                + this.getCurrRecord() + "]";
    }

}

点赞
收藏
评论区
推荐文章
风花雪月 风花雪月
2年前
警告Shadows built-in name
shadowsbuiltinname你取的函数名是内置函数名
风花雪月 风花雪月
2年前
警告Function name should be lowercase
用pyCharm时,常会出现警告信息:functionnameshouldbelowercase   函数名应该是小写 字母argumentnameshouldbelowercase参数名应该是小写字母variableinfunctionshouldbelowercase变量应该是小写字母 全是小写字母,可能与以往的习惯不大一
Wesley13 Wesley13
2年前
java将前端的json数组字符串转换为列表
记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang
Wesley13 Wesley13
2年前
Java解析XML
xml报文<?xmlversion'1.0'encoding'utf8'?<bookstore<bookid'1'<name冰与火之歌</name<author乔治马丁</author<year2014</yea
Wesley13 Wesley13
2年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
2年前
vb.net 使用ip查詢(Host Name)(WorkGroup Name)(MAC Address)
Subnbtstat(ByValipAsString)DimstrRst,strRst1,strRst2,strRst3AsStringDimn1,n2,n3AsIntegerTryDimpAsNewProcess()'用Process就可以p.StartInfo.FileName"
Stella981 Stella981
2年前
From表单提交的几种方式
<body<formaction"https://my.oschina.net/u/3285916"method"get"name"formOne"id"formId"name:<inputtype"text"name"name"pwd:<inputtyp
Stella981 Stella981
2年前
925. Long Pressed Name
题目链接:https://leetcode.com/problems/longpressedname/description/(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fleetcode.com%2Fproblems%2Flongpressedname%2Fdescript
Stella981 Stella981
2年前
Kafka多线程消费消息创建线程池并封装成Jar包
XML及属性配置1.业务处理(kiafka.worker.xml)<?xmlversion"1.0"encoding"UTF8"?<root<topics<!name:要消费的topic;<!worker:执行消费逻辑的worker,配置值为执行的类