Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210131] @Order, Enum, AWS S3 File upload(PutObjectRequest) #27

Open
JuHyun419 opened this issue Jan 31, 2021 · 0 comments
Open

[20210131] @Order, Enum, AWS S3 File upload(PutObjectRequest) #27

JuHyun419 opened this issue Jan 31, 2021 · 0 comments

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Jan 31, 2021

@order

  • Order 어노테이션은 해당 어노테이션이 달린 Component 혹은 bean의 순서를 정의함
  • Spring 4.0 이전에는 @order 어노테이션은 AspectJ 실행 순서에만 사용되었음
  • Spring 4.0 이후에는 collection의 components에 의존 순서를 지원함

Why Using Enum?

  • Type Safety(타입 안정성)
    // Fruit 클래스
    public static final int APPLE = 1;
    public static final int PEACH = 2;
    public static final int BANANA = 3;

    ... ...

    // Company 클래스
    public static final int APPLE = 1;
    public static final int GOOGLE = 2;
    public static final int FACEBOOK = 3;
  • 위 코드에서 과일 사과(APPLE) 와 회사 애플(APPLE)은 이름은 같으나 서로 다른 의미를 지닌다.
  • 하지만 위 코드처럼 사용하면 이름이 중복되고, 그 값(1)도 같기 때문에 타입 안정성을 보장하지 않는다.

if (Fruit.APPLE == Company.APPLE) {
    ...
}
  • 위 if 문은 비교 대상 조차가 아니며, false를 리턴해야 한다.
  • 하지만 현재 두 값은 모두 1이므로 컴파일 에러는 발생하지 않고, 심지어 결과도 true를 리턴한다!!
  • 따라서 Enum은 위처럼 상수를 클래스로 정의해서 관리할 때 얻을 수 있는 이점들을 모두 취하고, 가독성도 좋으며 상수들을 더욱 간단히 선언할 수 있도록 하기 위해 만들어졌다 !
  • EnumSet 의 allOf 메서드의 경우, 해당 Enum이 지니고 있는 모든 값을 리턴해준다.
enum Color {
    RED, GREEN, BLUE
}

EnumSet<Color> set1;
set1 = EnumSet.allOf(Color.class); // RED, GREEN, BLUE 모두를 반환해줌

Spring Boot - AWS S3 File Upload

  • AWS S3에 업로드시 PutObjectRequest 객체를 생성하는 두 가지 방법
      1. File 객체와 key 값을 이용해 만들기
      1. InputStream, key, 파일 정보(ContentType, file Length)을 이용해 만들기
      • key 값은 버킷 내에서 객체를 찾기위해 사용되는 고유 식별자



References

https://www.baeldung.com/spring-order
참고

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant