bladex自定义分页
生活随笔
收集整理的這篇文章主要介紹了
bladex自定义分页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大家好,我是雄雄,歡迎關注微信公眾號:雄雄的小課堂
前言
現在是2022年4月16日21:44:05!今天分享一個代碼段,個人覺得還是比較有參考性的。
實現代碼
整體思路是這樣的:
- 查詢當前用戶下的所有應用
- 查詢每個應用下的所有設備
- 將查詢出來的設備信息封裝在分頁工具類中
- 給前端傳回去分頁對象
比較麻煩的地方就在于,計算當前頁以及將當前頁的信息放在集合中傳出去,下面是實現代碼:
/*** 分頁 設備流程表*/@GetMapping("/list")@ApiOperationSupport(order = 2)@ApiOperation(value = "分頁", notes = "傳入equipment")public R<IPage<Equipment>> list(Equipment equipment, Query query) {//獲取當前用戶應用Application application = new Application();application.setUserId(AuthUtil.getUserId());List<Application> appList = applicationService.list(Condition.getQueryWrapper(application).select("app_id"));List<Equipment> equipmentList = new ArrayList<>();for(Application app : appList){QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();equipmentQueryWrapper.eq("application_id",app.getAppId());List<Equipment> eList = equipmentService.list(equipmentQueryWrapper);for(Equipment e : eList){equipmentList.add(e);}}//新的集合List<Equipment> equipmentListNew = new ArrayList<>();//當前頁//如果是第一頁,0-10//第二頁,11-20Integer current = (query.getCurrent()-1)*query.getSize();//頁大小Integer pageSize = query.getSize();if(equipmentList.size()<pageSize){pageSize = equipmentList.size();}else if(query.getCurrent()>1) {if (equipmentList.size() % query.getSize() != 0) {pageSize = (pageSize * (query.getCurrent() - 1)) + (equipmentList.size() % query.getSize());}else{pageSize = pageSize * query.getCurrent();}}for(int i = current;i<pageSize;i++){equipmentListNew.add(equipmentList.get(i));}IPage<Equipment> pages =new Page<>();pages.setRecords(equipmentListNew);pages.setSize(query.getSize());pages.setCurrent(query.getCurrent());pages.setTotal(equipmentList.size());return R.data(pages);}pages.setTotal(equipmentList.size());return R.data(pages);}總結
以上是生活随笔為你收集整理的bladex自定义分页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ChatGPT 移动端 9 月收入再创新
- 下一篇: iQOO 12系列或搭载6400万潜望长