@PostMapping("/getMonthReport") public ApiResult<IPage<OilMonthReportVo>> getMonthReport(@RequestBody String json) { initPage(json); String month = getParamString("month"); List<OilMonthReportVo> monthReportList = oilMonthReportNoTankService.getMonthReport(month); int count = monthReportList.size(); if (count>1){ Collections.reverse(monthReportList); // Collections.sort(monthReportList, new Comparator<OilMonthReportVo>() { // @Override // public int compare(OilMonthReportVo o1, OilMonthReportVo o2) { // return o2.getMonth().compareTo(o1.getMonth()); // } // }); } Page<OilMonthReportVo> page = new Page<>(getPage(), getSize()); List<OilMonthReportVo> pageList = new ArrayList<>(); //计算当前页第一条数据的下标 计算集合的下标 ,翻页的时候 下标从20开始 int currId = getPage()>1 ? (getPage()-1)*getSize():0; // 计算循环的次数 条件为:小于20(一页展示多少条) 并且 小于总条数 -下标数 = 真正的次数 for (int i=0; i<getSize() && i<count - currId;i++){ pageList.add(monthReportList.get(currId+i)); } page.setSize(getSize()); page.setCurrent(getPage()); page.setTotal(count); page.setRecords(pageList); page.setPages(count %getSize() == 0 ? count/getSize() :count/getSize()+1); return new SuccessResult<>(page);
基于mybatisplus ,对查询list分页
最新推荐文章于 2024-07-25 10:21:31 发布
本文介绍了一个API接口,用于获取按月的油品报告数据,对数据进行排序和分页处理,以便于分析和展示。通过MonthReportVo对象展示数据,并使用Comparator和Collections工具进行高效处理。
摘要由CSDN通过智能技术生成