zoukankan      html  css  js  c++  java
  • 工作中的各种小技巧

    今天写文档,头大的一p。。。。于是看是想总结点有用的东西

    第一:集合元素的删除

    由于集合的下标问题,对其删除时需使用迭代器

    如下:一个现有list集合,处理起来非常便利

    List<ShopSimpleEpcInfo> list=checkService.getLoseSkuAndEpc(checkId);

    Iterator<ShopSimpleEpcInfo> iter = list.iterator();
    while (iter.hasNext()) {
    ShopSimpleEpcInfo shopSimpleEpcInfo = iter.next();
    if (shopSimpleEpcInfo.getWaitOnshelf()==0) {
    iter.remove();
    }
    }



    第二点;对于经常在返回的javabean中增加其他属性,又不想改变javabean的时候,可以使用一下方法,用string和json之间的互相转换,便利搞定

    JSONArray arrResult = new JSONArray();
    // 遍历最外层结果
    for (AreaShopInfo area : list)
    {
    //转成jsonObject
    JSONObject jArea = JSON.parseObject(JSON.toJSONString(area));
    //创建信的jsonlist
    JSONArray jArrList = new JSONArray();
    //对第一层进行遍历
    for (JHShopInfo shop : area.getList())
    {
    // 转 shop 为 json
    JSONObject jShop = JSON.parseObject(JSON.toJSONString(shop));
         //将需要添加的属性进行json添加
    jShop.put("orderCount", mapOrderCount.get(shop.getShopId()));
          // 将jshop重新驾到json集合中
    jArrList.add(jShop);
    }
      //恢复外层结构
    jArea.put("list", jArrList);
    jArea.put("orgParentName", area.getOrgParentName());
      返回
    arrResult.add(jArea);
    }




    
    
    如有错误,请邮件zs253499660@sina.com,如有更好的方法,可以推荐
  • 相关阅读:
    laravel blog 一
    dede:channelartlist currentstyle高亮显示
    dede调用导航/幻灯
    rmp 安装LNMP环境
    无极分类之子孙树、父辈树
    创始人 密码
    mysql报错显示法文解决办法
    渐变色背景
    laravel sendmail
    工作流系统webservice服务
  • 原文地址:https://www.cnblogs.com/senjiang/p/9627519.html
Copyright © 2011-2022 走看看