public List<Object> queryAll(@RequestParam(required=false,defaultValue="0") Integer page, @RequestParam(required=false,defaultValue="0") Integer pageSize, @RequestParam(required=false,defaultValue="0") Integer id){ PageHelper.startPage(page, pageSize); List<Object> dataList = new ArrayList<>(); List<A> aList = aService.queryAll(id); List<B> bList = bService.queryAll(id); //重点在下面 if (pageSize == 0) { PageInfo<A> a = new PageInfo<>(aList ); PageInfo<B> b = new PageInfo<>(bList ); dataList.addAll(a.getList()); dataList.addAll(b.getList()); return dataList; } else { //根据pageSize设定总共返回的数据条数,确保返回的数据总数不会超过pageSize int totalSize = aList.size() + bList.size(); int endIndex = Math.min(totalSize, pageSize); //返回的 suppliesStockList 数据条数不会超过 endIndex dataList.addAll(aList.subList(0, Math.min(aList.size(), endIndex))); dataList.addAll(bList.subList(0, Math.max(0, endIndex - bList.size()))); return dataList; } }
上述代码将两个不同实体类的数据进行分页的处理,当pageSize为0,表示将所有的数据返回,不为0就按照pageSize的个数返回对应个数的数据