美文网首页
Java 子类集合转父类结合

Java 子类集合转父类结合

作者: 私人云笔记_骁勇波波 | 来源:发表于2023-03-08 09:48 被阅读0次

    子类集合转父类结合:

    @Override

        public ArrayList<UserInfo> getOwnedUserList(Account account) {

            AccountTypeEnum accountType = AccountTypeEnum.getEnum(value));

           // 父类集合

            ArrayList<UserInfo> ownedUserList = new ArrayList<>();

            switch (accountType) {

                case Sup:

                    //子类集合

                    ArrayList<Account> tempUserList = getAccountListByParentId(account.getId());

                    // 子类集合转父类结合

                    ownedUserList.addAll(tempUserList);

                    break;

                case HC:

                    P p = pService.getPByAccountId(account.getId());

                   default:

                    break;

            }

            return ownedUserList;

        }

    1. ExtUser

    @Data

    @Builder

    @AllArgsConstructor

    @NoArgsConstructor

    public class ExtUser extends Account {

        public Long pCount;

    }

    2. Account

    @TableName("account")

    @Data

    public class Account extends UserInfo implements Serializable {

        private static final long serialVersionUID = 1L;

        private String password;

        private Integer deleteFlag;

    }

    3. UserInfo

    @Data

    public class UserInfo implements Serializable {

        private static final long serialVersionUID = 1L;

        @TableId(value = "id", type = IdType.AUTO)

        private Integer id;

        private String username;

    }

    相关文章

      网友评论

          本文标题:Java 子类集合转父类结合

          本文链接:https://www.haomeiwen.com/subject/slanldtx.html