手动分页

public Object getTradeChinaDataTab(String sql ,int page){
        Query query = entityManager.createNativeQuery(sql);
        List objecArraytList = query.getResultList();
        List> list = new ArrayList<>();
        for(Object ob: objecArraytList){
            Object[] obj = (Object[])ob;
            Map mapf = new HashMap<>();
                mapf.put("value", Double.parseDouble(String.valueOf(obj[0])));
                mapf.put("country", String.valueOf(obj[1]));    
                mapf.put("province", String.valueOf(obj[2]));   
                mapf.put("time", String.valueOf(obj[3]));   
                list.add(mapf);
            
        }
                
        int index;
        if(page!=1){
            index = page;
        }else{
            index = 1;
        }
        List> plist = new ArrayList<>();
        int pageSize = 10;
        int total = 0;
        if(list!=null){
            total = list.size()%pageSize==0?list.size()/pageSize:list.size()/pageSize + 1;
            for(int i=(index-1)*pageSize;i<(pageSize*index map = new HashMap<>();
        map.put(LIST, plist);
        map.put(TOTALPAGES, total);
        map.put(CURRENTPAGE, index);
        if(list.size()!=0){
            map.put(TOTALRECORDS, list.size());
        }else{
            map.put(TOTALRECORDS, 0);
        }
        return map;
    }

你可能感兴趣的:(手动分页)