1. 程式人生 > >分頁封裝 PageInfo

分頁封裝 PageInfo

 

MAVEM

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.0.1</version>
        </dependency>

 

 

分頁可以直接只用Map接收

@Override
    public PageInfo<Map> findPaysByUserid(Map params) {
        PageHelper.startPage((Integer)params.get("currentPage"), (Integer)params.get("pageSize"));
        List<Map> userPays = userDataMapper.findPaysByUserid(params);
        PageInfo<Map> pageInfo = new PageInfo<Map>(userPays);
        return pageInfo;
    }

 

 

 



import java.io.Serializable;

/*
 *
 * PageInfo
 * @author wangwei
 * @date 2019/1/9
  * @param null 
 * @return 
 */
public class PageInfo implements Serializable{


    private static final long serialVersionUID = 1L;
    /**
     * 總記錄數
     */
    private Long total;
    /**
     * 總頁數
     */
    private Long totalPages;
    /**
     * 當前頁
     */
    private Integer pageNo;
    /**
     * 頁記錄數
     */
    private Integer pageSize;

    public PageInfo(Long total) {
        this.total = total;
    }

    public PageInfo(Long total, Integer pageNo,
                    Integer pageSize) {
        this.total = total;
        this.totalPages = (total - 1) / pageSize + 1;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    public static PageInfo page(Long total) {
        return new PageInfo(total);
    }

    public static PageInfo page( Long total, Integer pageNo,
                                 Integer pageSize) {
        return new PageInfo(total, pageNo, pageSize);
    }

    public Long getTotal() {
        return total;
    }

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

    public Long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Long totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

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