zoukankan      html  css  js  c++  java
  • java 遍历中为对象添加元素

    publie Object getaddress(){

    List<MemberAddress> memberAddressList = new ArrayList<MemberAddress>();
    try {
    // 通过memberId查询用户所有地址
    memberAddressList = memberAddressService.getByMemberId(member.getId());
    } catch (Exception e) {
    return new APIResult(GlobalConstantsUtil.GENERAL_ERROR, "获取字段失败");
    }
    // 若memberAddressList集合为空,返回为空
    if (memberAddressList == null || memberAddressList.size() == 0) {
    return APIResult.createSuccess();
    }
    // 创建MemberAddressVO3集合
    List<MemberAddressVO3> list = new ArrayList<MemberAddressVO3>();
    // 遍历MemberAddress,将其值赋予MemberAddressVO3对象
    for (int i = 0; i < memberAddressList.size(); i++) {
    MemberAddress memberAddress = memberAddressList.get(i);
    MemberAddressVO3 memberAddressVO3 = new MemberAddressVO3(); //新创建对象(在循环中)

    memberAddressVO3.setMemberAddressId(memberAddress.getId());
    memberAddressVO3.setAddressStatus(memberAddress.getAddressStatus());
    memberAddressVO3.setCityId(memberAddress.getCityId());
    memberAddressVO3.setConsignee(memberAddress.getConsignee());
    memberAddressVO3.setContactMobilePhone(memberAddress.getContactMobilePhone());
    memberAddressVO3.setCreateTime(memberAddress.getCreateTime());
    memberAddressVO3.setDetail(memberAddress.getDetail());
    memberAddressVO3.setMemberId(memberAddress.getMemberId());
    memberAddressVO3.setAddressStatusDefault(false);
    if ((memberAddress.getAddressStatus()
    & GlobalConstantsUtil.MEMBER_ADDRESS_DEFAULT) == GlobalConstantsUtil.MEMBER_ADDRESS_DEFAULT) {
    memberAddressVO3.setAddressStatusDefault(true);
    }
    // 将获得的MemberAddressVO3对象添加至MemberAddressVO3的list集合中
    list.add(memberAddressVO3);
    }

    retrun list;

    }

  • 相关阅读:
    [最短路-Floyd][并查集]SSL P2344 刻录光盘
    [并查集][bfs]JZOJ P3973 黑白数
    [容斥原理][dp]JZOJ P3056 数字
    [归并排序][枚举]JZOJ P3967 Counting Friends
    [二分][贪心]JZOJ P3996 Sabotage
    [最短路-Floyd][数学]Luogu P1552 牛的旅行
    [序列dp]Luogu P1415 拆分数列
    [多项式求逆]JZOJ 3303 城市规划
    [树链剖分]JZOJ 2677 树A
    [费用流]luogu P3159 交换棋子
  • 原文地址:https://www.cnblogs.com/qqzhulu/p/10258234.html
Copyright © 2011-2022 走看看