java开发中遇到的一些问题

Jackson

1.HashMap相关问题

1.1HashMap存key,value,key会有重复的,value会有多个值,选取此方式进行存取,动态获取key,value取list,若满足条件,list一直add,key覆盖掉之前的,list一直在增加。

HashMap<String, List<ScatteredPrescriptionDetail>> preDetailMap=new HashMap<String, List<ScatteredPrescriptionDetail>>();
            for (int i=0;i<prescriptionDetailList.size();i++) {
                ScatteredPrescriptionDetail scatteredPrescriptionDetail = prescriptionDetailList.get(i);
                if("Y".equals(scatteredPrescriptionDetail.getIsSubOrder())){
                    if (!preDetailMap.containsKey(scatteredPrescriptionDetail.getParentOrderSN())) {
                        List<ScatteredPrescriptionDetail> tmpList=new ArrayList<ScatteredPrescriptionDetail>();
                        tmpList.add(scatteredPrescriptionDetail);
                        preDetailMap.put(scatteredPrescriptionDetail.getParentOrderSN(), tmpList);
                    }
                    else {
                        System.out.println();
                        preDetailMap.get(scatteredPrescriptionDetail.getParentOrderSN()).add(scatteredPrescriptionDetail);
                    }
                }
                else if("N".equals(scatteredPrescriptionDetail.getIsSubOrder())){
                    faList.add(scatteredPrescriptionDetail);
                }
            }

1.2关于计算日期上一周与下一周的问题

public String changeCurrentTime()throws Exception{
        String before = getParameter("before");
        String flag = getParameter("flag");
        String[] split=before.split("-");
        int year=Integer.valueOf(split[0]).intValue();
        int mon=Integer.valueOf(split[1]).intValue();
        int day=Integer.valueOf(split[2]).intValue();
        String after="";
        if("B".equals(flag)) {
            int tmpday=0;
            if(day<=7) {
                tmpday=7-day;
                mon=mon-1;
                day=new Date(year, mon, 0).getDate()-tmpday;
                if(mon<=0) {
                    year=year-1;
                    mon=12;
                    day=new Date(year, mon, 0).getDate();
                }
            }else {
                day=day-7;
            }
            after=String.valueOf(year)+"-";
            after=after+String.valueOf((mon<10?String.valueOf("0"+mon):String.valueOf(mon)))+"-";
            after=after+String.valueOf(day<10?String.valueOf("0"+day):String.valueOf(day));
        }
        if("A".equals(flag)) {
            int tmpday=0;
            day=day+7;
            if(day>new Date(year, mon, 0).getDate()) {
                tmpday=new Date(year, mon, 0).getDate();
                mon=mon+1;
                day=day-tmpday;
                if(mon>12) {
                    year=year+1;
                    mon=1;
                }
            }
            after=String.valueOf(year)+"-";
            after=after+String.valueOf((mon<10?String.valueOf("0"+mon):String.valueOf(mon)))+"-";
            after=after+String.valueOf(day<10?String.valueOf("0"+day):String.valueOf(day));
        }
        return after;
    }
阅读 176
1 声望
0 粉丝
0 条评论
1 声望
0 粉丝
宣传栏