반응형
public enum Company {

    COMPANY_01("01", "카카오"),
    COMPANY_02("02", "네이버"),
    COMPANY_03("03", "GS25"),
    COMPANY_04("04", "넥슨"),
    COMPANY_05("05", "애플"),

    String code;
    String desc;

    Company(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
		return code;
	}

	public String getDesc() {
		return desc;
	}
}
	//map에 담음
	public static final Map<String, String> companyMap = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(Company::getCode, Company::getDesc)));

	//map에 넣은 뒤 특정 값 찾기
    public static String findDesc(String description) {
        return Optional.ofNullable(companyMap.get(description)).orElse("UNKNOWN");
    }​

 

 

 


		//enum list에 담기
		List<SelectBoxVo> list = new ArrayList<>(){};

		for(Company code : Stream.of(Company.values()).collect(Collectors.toList())){
			list.add(SelectBoxVo.builder().code(code.getCode()).label(code.getDesc()).build());
		}

 

 

반응형

+ Recent posts