天猫整站(简易版)SSM——工具类

一、图片处理

二、Mybatis逆向工具

三、分页

新增Page这个类专门为分页提供必要信息

3.1 属性

int start; 开始位置

int count; 每页显示的数量

int total; 总共有多少条数据

String param; 参数(分页时传递需要的参数)

3.2 方法

getTotalPage 根据 每页显示的数量count以及总共有多少条数据total,计算出总共有多少页

getLast 计算出最后一页的数值是多少

isHasPreviouse 判断是否有前一页

isHasNext 判断是否有后一页

3.3 功能

配合第三方分页工具PageHelper完成分页

3.4 代码

package util;

/**
 * @Author: 98050
 * Time: 2018-09-17 19:27
 * Feature:
 */
public class Page {
    /**
     *  每页从第几个开始
     */
    private int start;
    /**
     * 每页显示的个数
     */
    private int count;
    /**
     * 总数
     */
    private int total;
    /**
     * 参数
     */
    private String param;

    /**
     * 默认每页显示5条
     */
    private static final int defaultCount = 5;

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public Page(){
        count = defaultCount;
    }

    public Page(int start,int count){
        /**
         * 先调用无参构造方法
         */
        this();
        this.start = start;
        this.count = count;
    }

    public boolean isHasPreviouse(){
        if(start == 0) {
            return false;
        }
        return true;
    }

    public boolean isHasNext(){
        if (start == getLast()){
            return false;
        }else {
            return true;
        }
    }

    public int getTotalPage(){
        int totalPage;

        if (total % count == 0){
            totalPage = total / count;
        }else {
            totalPage = total / count +1;
        }
        if (totalPage == 0){
            totalPage = 1;
        }
        return totalPage;
    }

    public int getLast(){
        int last;

        if (total % count == 0){
            last = total - count;
        }
        else {
            last = total - total % count;
        }
        last = last < 0 ? 0 : last;
        return last;
    }

    @Override
    public String toString() {
        return "Page{" +
                "start=" + start +
                ", count=" + count +
                ", total=" + total +
                ", param='" + param + '\'' +
                '}';
    }
}

猜你喜欢

转载自blog.csdn.net/lyj2018gyq/article/details/82803944