若依 SpringBoot实现分页问题

由于若依框架分页的实现,后端有很多限制因素,具体影响因素参考若依官网的在线文档

http://doc.ruoyi.vip/),所以就自己写了一个后端实现分页的代码;

public TableDataInfo selectCourseManage(CusCourseManage cusCourseManage,String userId) {
        //查询出来的数据
        List<CusNewManage> list = cusCourseManageService.selectNewCourseManages(userId,cusCourseManage.getType()); 
        //筛选出符合条件的数据,放入resultList中
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); 
        if (!list.isEmpty()) {
            for (CusNewManage cusNewM : list) {
                if (StringUtils.isNotBlank(cusNewM.getCourseManage())) {
                    CusCourseManage courseManage = cusCourseManageService
                            .selectCusCourseManageById(Long.parseLong(cusNewM.getCourseManage()));
                    Map<String, Object> resultMap = new HashMap<String, Object>();
                    resultMap.put("type", courseManage.getType());
                    resultMap.put("passTime", courseManage.getPassTime());
                    if (courseManage.getFlag().equals("0")) {
                        resultMap.put("flag", true);
                    } else {
                        resultMap.put("flag", false);
                    }
                    resultMap.put("materialId", courseManage.getMaterialId());
                    resultMap.put("id", cusNewM.getId());
                    resultMap.put("projectName", cusNewM.getProjectName());
                    resultMap.put("courseType", cusNewM.getCourseType());
                    resultList.add(resultMap);
                }
            }
        }

        //第几页
        Long num = Long.valueOf(cusCourseManage.getPageNum()); 
        //每页条数
        Long size = Long.valueOf(cusCourseManage.getPageSize()); 
        int number = 0;
        //判断是否为第一页
        if (num!=1){ 
            num--;
            number = Math.toIntExact(num * size);
            size = (num * size)+size;
        }

        //定义要显示的list
        List<Map<String, Object>> pageList = new ArrayList<Map<String, Object>>(); 
        for (int i=number;i<size;i++){
            if (resultList.size()>i){
                pageList.add(resultList.get(i));
            }else {
                break;
            }
        }
        return getDataTablePage(pageList,resultList.size());
    }

    public TableDataInfo getDataTablePage(List<?> list,int count) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list); //要显示的list
        rspData.setTotal(count); //总数
        return rspData;
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值