基于mybatisplus ,对查询list分页

本文介绍了一个API接口,用于获取按月的油品报告数据,对数据进行排序和分页处理,以便于分析和展示。通过MonthReportVo对象展示数据,并使用Comparator和Collections工具进行高效处理。
摘要由CSDN通过智能技术生成

    @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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值