手动分页切割和反射实体类转化为json

1.手动分页切割

List<ZLBDistrictAndCountyStatisticsVo> result = statisticsService.findAll(javaBean,begin,end,pp);

        
List<ZLBDistrictAndCountyStatisticsVo> dataList ;
//获取总页数        
int tempNum = result.size()/pp.getPageMaxSize();
        int maxPageNum = result.size()%pp.getPageMaxSize() > 0 ? tempNum+1 : tempNum;

//如果每一页的数量大于数据源总数量,切割全部
        if(pp.getPageMaxSize() > result.size()){
            dataList = result;
        }else 
//如果勾选页数等于最大页数,直接切割从开始到结尾                       
            if(pp.getCurrentPageNumber() == maxPageNum){
            dataList = result.subList((pp.getCurrentPageNumber()-1)*pp.getPageMaxSize(),result.size());
        }else 
//如果是勾选中间页数,直接从中间开始,到中间结束          
            {
            dataList = result.subList((pp.getCurrentPageNumber()-1)*pp.getPageMaxSize(),pp.getCurrentPageNumber()*pp.getPageMaxSize());
        }
        Page<ZLBDistrictAndCountyStatisticsVo> page = new Page(pp.getCurrentPageNumber(),pp.getPageMaxSize(),dataList,result.size(),pp.getPageDiv());

2.反射实体类转化为map

List<ZLBStatisticsEverydayVo> result = statisticsService.findAll(statisticsEveryday,begin,end,pp);
        List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();

        //TODO
        for (ZLBStatisticsEverydayVo vo : result) {
            Map<String, Object> stringObjectMap = objectToMap01(vo);
            resultList.add(stringObjectMap);
        }




// 工具方法
public static Map<String, Object> objectToMap01(Object obj) throws Exception {
        if (obj == null) {
            return null;
        }
        Map<String, Object> map = new HashMap<String, Object>();
//获取实体类的所有属性
        Field[] declaredFields = obj.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            //设置为true,允许访问私有属性
            field.setAccessible(true);
            if ("wyht".equals(field.getName()) && null!=field.getName() && -1 == (Integer) field.get(obj)){
                map.put(field.getName(),"-");
            }else {
                map.put(field.getName(),field.get(obj));
            }
        }
//获取该类,父亲的所有属性    
        Field[] declaredFields1 = obj.getClass().getSuperclass().getDeclaredFields();
        for (Field field : declaredFields1) {
            field.setAccessible(true);
            if ("wyht".equals(field.getName()) && null!=field.getName() && -1 == (Integer) field.get(obj)){
                map.put(field.getName(),"-");
            }else {
                map.put(field.getName(),field.get(obj));
            }
        }
        return map;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值