java内存分页

List<BofCytProduct> bofCytProductArray=getAllOnProdcuct();
            List<BofCytProduct> list = new ArrayList<BofCytProduct>();
            for(BofCytProduct bofCytProduct:bofCytProductArray){
                if(!ProductCodeConstants.JI_JIN.equals(bofCytProduct.getTypeCode())){
                    list.add(bofCytProduct);
                }
            }
            Collections.sort(list, new CompareProduct());
            
            int count = list.size();
            QueryResult<CytProductListDto> queryResult = new QueryResult<CytProductListDto>(count, pager.getPageSize(),
                    pager.getPageNumber());
            // 构造参数
            List<BofCytProduct> cytProductList = new ArrayList<BofCytProduct>();
            if(list.size()>(queryResult.getIndexNumber()+queryResult.getPageSize())){
                cytProductList.addAll(list.subList(queryResult.getIndexNumber(), queryResult.getIndexNumber()+queryResult.getPageSize()));
            }else{
                cytProductList.addAll(list.subList(queryResult.getIndexNumber(),count));
            }


/**
     * 根据产品优先级比较,比如1、2,1放在第一位<br>
     * 
     * @author 赵毅(13092551)
     */
    private static class CompareProduct implements Comparator<BofCytProduct>, Serializable {
        
        private static final long serialVersionUID = -9212971658450782319L;

        @Override
        public int compare(BofCytProduct o1, BofCytProduct o2) {
            Integer product1 = Integer.parseInt(o1.getProductPriority());
            Integer product2 = Integer.parseInt(o2.getProductPriority());
            return product1.compareTo(product2);
        }

}

如果数据量大,这个方式应该不适合。


你可能感兴趣的:(java,分页)