java 后台分页

 public static Page getGson(Map params, Resource json) throws IOException {

        String areaData = IOUtils.toString(json.getInputStream(), Charset.forName("UTF-8"));
        JSONObject obj = JSONObject.parseObject(areaData);

        JSONObject object = obj.getJSONObject("pageVO");
        Page page = new Page();
        int pageNumer = Integer.parseInt((String) params.get("pageNumber"));
        int pageSize = Integer.parseInt((String) params.get("pageSize"));
        page.setPageSize(pageSize);

        int totalRows = Integer.parseInt(object.getString("totalRows"));
        page.setTotalNumber(totalRows);
        page.setPageIndex(pageNumer);
        // 总记录数
        int startRow = page.getStart();
        int endRow = page.getEnd();


        Map jsonMap = CommonToJson.jsonToBean(areaData);
        List> totalList = (List>) jsonMap.get("result");
        if(endRow>totalRows){
            endRow=totalRows-1;
        }
        List> newList=totalList.subList(startRow,endRow);
        page.setList(newList);

        return page;
    }

 

你可能感兴趣的:(JAVA)