分页使用的公共类

  1 package com.shi.common.pagination;
  2 
  3 import java.io.Serializable;
  4 import java.util.ArrayList;
  5 import java.util.List;
  6 
  7 /**
  8  * 分页内容信息
  9  * <p>
 10  * Created by Shi on 2017/1/18.
 11  */
 12 public class Pageable<T> implements Serializable {
 13     private Integer pageNumber;
 14     private Integer pageNum;
 15     private Integer pageSize;
 16     private Integer totalPage;
 17     private Long totals;
 18     private String search;
 19     private String keyWord;
 20     private List<T> content = new ArrayList<T>();
 21 
 22     public Pageable() {
 23         this.totalPage = 0;
 24         this.pageNumber = 1;
 25         this.pageNum=1;
 26         this.pageSize = 10;
 27     }
 28 
 29     public Pageable(Integer pageNumber, Integer pageSize, Integer totalPage, String search, List<T> content) {
 30         this.pageNumber = pageNumber;
 31         this.pageSize = pageSize;
 32         this.totalPage = totalPage;
 33         this.search = search;
 34         this.content = content;
 35     }
 36 
 37     public Pageable(Integer pageNumber, Integer pageSize, Integer totalPage, String search, String keyWord, List<T> content) {
 38         this.pageNumber = pageNumber;
 39         this.pageSize = pageSize;
 40         this.totalPage = totalPage;
 41         this.search = search;
 42         this.keyWord = keyWord;
 43         this.content = content;
 44     }
 45 
 46     public Integer getPageNum() {
 47         return pageNum;
 48     }
 49 
 50     public void setPageNum(Integer pageNum) {
 51         this.pageNumber=pageNum;
 52         this.pageNum = pageNum;
 53     }
 54 
 55     public void setKeyWord(String keyWord) {
 56         this.keyWord = keyWord;
 57     }
 58 
 59     public String getKeyWord() {
 60         return keyWord;
 61     }
 62 
 63     public Integer getPageNumber() {
 64         return pageNumber;
 65     }
 66 
 67     public void setPageNumber(Integer pageNumber) {
 68         this.pageNumber=pageNumber;
 69         this.pageNum = pageNumber;
 70     }
 71 
 72     public Integer getPageSize() {
 73         return pageSize;
 74     }
 75 
 76     public void setPageSize(Integer pageSize) {
 77         this.pageSize = pageSize;
 78     }
 79 
 80     public Integer getTotalPage() {
 81         return totalPage;
 82     }
 83 
 84     public void setTotalPage(Integer totalPage) {
 85         this.totalPage = totalPage;
 86     }
 87 
 88     public String getSearch() {
 89         return search;
 90     }
 91 
 92     public void setSearch(String search) {
 93         this.search = search;
 94     }
 95 
 96     public List<T> getContent() {
 97         return content;
 98     }
 99 
100     public void setContent(List<T> content) {
101         this.content = content;
102     }
103     
104     public Integer getFirst() {
105         return (pageNumber - 1) * pageSize;
106     }
107 
108     public Long getTotals() {
109         return totals;
110     }
111 
112     public void setTotals(Long totals) {
113         this.totals = totals;
114     }
115 }
View Code

使用方法controller里面

 1 @RequestMapping("/invoice/list")
 2     public String invoiceList(ModelMap modelMap, Pageable<InvoiceEntity> pageable,InvoiceStatusEnum statusEnum,String startdate, String enddate){
 3         Integer status = null;
 4         if (null != statusEnum) {
 5             status = statusEnum.ordinal();
 6         }
 7         Pageable<InvoiceEntity> page = invoiceService.queryPage(pageable, status, startdate, enddate);
 8         modelMap.addAttribute("page", page);
 9         modelMap.addAttribute("status", InvoiceStatusEnum.values());
10         Map<String, Object> conditon = new HashMap<String, Object>();
11         conditon.put("startDate", startdate);
12         conditon.put("endDate", enddate);
13         conditon.put("statusEnum", statusEnum);
14         modelMap.addAttribute("condition", conditon);
15         modelMap.addAttribute("menuIndx",8);
16         return "/invoice/list";
17     }
View Code

service里面

 1 @Override
 2     public Pageable<InvoiceEntity> queryPage(Pageable<InvoiceEntity> pageable, Integer status, String startDate, String endDate) {
 3         Page<InvoiceEntity> page = PageHelper.startPage(pageable.getPageNumber(), pageable.getPageSize());
 4         List<InvoiceEntity> list = null;
 5         if (null==status&&StringUtil.isEmpty(startDate)&&StringUtil.isEmpty(endDate)) {
 6             list = invoiceEntityMapper.selectAll();
 7         } else {
 8             list = invoiceEntityMapper.selectPagable(status, startDate, endDate);
 9         }
10         pageable.setContent(list);
11         pageable.setTotalPage(page.getPages());
12         return pageable;
13     }
View Code

 

转载于:https://www.cnblogs.com/hjb90/p/7280846.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值