javalist for paging data to page

Keywords: Database

Because a page of the project is displayed from multiple sources, it is impossible to query the database and page, and the data volume is not large, so I have to use memory page, but I am stupid. I found a page on the Internet for half a day to improve it to fit me, and finally finished paging, but the current barrier has become filtering again, so I will not record it temporarily

  • Paste the paging model first
public class Page {

        private Integer currentPage;//Current page
        private int pageSize;//Number of records per page
        private int totalPage;//PageCount
        private List<?> dataList;//Data displayed per page
        private int star;//Start data

        public Integer getCurrentPage() {
            return currentPage;
        }
        public void setCurrentPage(Integer currentPage) {
            this.currentPage = currentPage;
        }
        public int getPageSize() {
            return pageSize;
        }
        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }
        public int getTotalPage() {
            return totalPage;
        }
        public void setTotalPage(int totalPage) {
            this.totalPage = totalPage;
        }
        public List<?> getDataList() {
            return dataList;
        }
        public void setDataList(List<?> dataList) {
            this.dataList = dataList;
        }
        public int getStar() {
            return star;
        }
        public void setStar(int star) {
            this.star = star;
        }
}
  • Then the list data received by the controller layer is paged
List<CountryEntity> list = page.getList();
        Page Page = new Page();
        //list data found

        //The first page is the first one
        if (Page.getCurrentPage() == null) {
            Page.setCurrentPage(1);
        } else {
            Page.setCurrentPage(Page.getCurrentPage());
        }
        //Set 10 pieces of data per page
        Page.setPageSize(count);
        //Number of starts per page
        Page.setStar((Page.getCurrentPage() - 1) * count);
        //Size of list
        int totalCount = list.size();
        //Set total pages
        Page.setTotalPage(totalCount % 10 == 0 ? totalCount / 10 : totalCount / 10 + 1);
        //Intercept list
        Page.setDataList(list.subList(Page.getStar(),totalCount-Page.getStar()>Page.getPageSize()?Page.getStar()+Page.getPageSize():totalCount));

        page.setList((List<CountryEntity>) Page.getDataList());

        return ServerResponse.createBySuccess(page);
  • Follow up filter to upload

Posted by labmixz on Mon, 25 Nov 2019 07:59:49 -0800