Phase 3

-ing

Test Code

Exception

ν•΄λ³΄κ³ μ‹Άμ—ˆλ˜ 도메인 둜직

@EntityListener(AuditingEntityListener.class)

  • BaseEntity(abstract class)λ₯Ό μƒμ„±ν•˜κ³ , 이 extendsν•˜μ—¬ createdAt, updatedAt ν•„λ“œμ™€ 같은 κ³΅ν†΅μœΌλ‘œ λ“€μ–΄κ°€λŠ” ν•„λ“œλ₯Ό 생성해쀀닀.

  • Sping main λ©”μ„œλ“œκ°€ λ“€μ–΄μžˆλŠ” νŒŒμΌμ— @EnableJpaAuditing μ–΄λ…Έν…Œμ΄μ…˜μ„ λΆ™μ—¬μ•Ό extends κ°€ 잘 μž‘λ™ν•˜μ—¬ μ§„μž…ν΄λž˜μŠ€μ— μœ„μ˜ μ–΄λ…Έν…Œμ΄μ…˜μ„ λΆ™μ—¬μ£Όμ—ˆλ‹€.

  • @EntityListener(AuditingEntityListener.class)λ₯Ό BaseEntity μͺ½μ— λΆ™μ—¬μ£Όλ©΄ @EnableJpaAuditing μ–΄λ…Έν…Œμ΄μ…˜μ„ 뢙여주지 μ•Šμ•„λ„ 잘 μž‘λ™ν•œλ‹€.

μžλ°” 직렬화 Serializable

ref

Java Abstraction _ abstract classes and method

Data abstraction is the process of hiding certain details and showing only essential information to the user. Abstraction can be achieved with either abstract classes or interfaces .

βœ”οΈ abstract classes and method

abstract class Animal {
  // Abstract method (does not have a body)
  public abstract void animalSound();
  // Regular method
  public void sleep() {
    System.out.println("Zzz");
  }
}

// Subclass (inherit from Animal)
class Pig extends Animal {
  public void animalSound() {
    // The body of animalSound() is provided here
    System.out.println("The pig says: wee wee");
  }
}

class Main {
  public static void main(String[] args) {
    Pig myPig = new Pig(); // Create a Pig object
    myPig.animalSound();
    myPig.sleep();
  }
}

βœ”οΈ Interface

An interface is a completely "abstract class" that is used to group related methods with empty bodies. To access the interface methods, the interface must be "implemented" (kinda like inherited) by another class with the implements keyword (instead of extends). The body of the interface method is provided by the "implement" class .

// Interface
interface Animal {
  public void animalSound(); // interface method (does not have a body)
  public void sleep(); // interface method (does not have a body)
}

// Pig "implements" the Animal interface
class Pig implements Animal {
  public void animalSound() {
    // The body of animalSound() is provided here
    System.out.println("The pig says: wee wee");
  }
  public void sleep() {
    // The body of sleep() is provided here
    System.out.println("Zzz");
  }
}

class Main {
  public static void main(String[] args) {
    Pig myPig = new Pig();  // Create a Pig object
    myPig.animalSound();
    myPig.sleep();
  }
}

ref

@SpringBootApplication

ref

@Valid

Test Code

ref

Long -> BoardId λ°Έλ₯˜ νƒ€μž…

  • mapping ν•  λ•Œ λ²ˆκ±°λ‘œμ›Œμ„œ κ²°κ΅­ ν•œ 번 μ‹œλ„ν–ˆλ‹€κ°€, Long Id 둜 λ³€κ²½ν–ˆλ‹€.

Optional

@Builder.Dafult

  • μ²˜μŒμ— @DynamicInsert 뢙이고 @Column(Default= 'μ–΄μ©Œκ΅¬ ') ν•΄μ„œ μž‘μ„±ν–ˆλ‹€.

@DynamicInsert λž€...?

ref

final, static, final static

ref

reflection

μ ‘κ·Ό μ œν•œμž μ‹€μ œλ‘œ μ‚¬μš©ν•΄λ³΄κΈ°

enum

ref

ResponseEntity

Dependencies

mapstruct

generated 파

Logback + slf4j

lombok

e

@Getter - 이 μ• λ„ˆν…Œμ΄μ…˜μ΄ μ§€μ •λœ ν•„λ“œμ— λŒ€ν•΄ getter λ©”μ„œλ“œλ₯Ό μžλ™ μƒμ„±ν•œλ‹€. λ§Œμ•½ ν΄λž˜μŠ€μ— 이 μ• λ„ˆν…Œμ΄μ…˜μ„ μ‚¬μš©ν•˜λ©΄ ν•΄λ‹Ή 클래슀의 λͺ¨λ“  private ν•„λ“œμ— λŒ€ν•΄ getter λ©”μ„œλ“œλ₯Ό μƒμ„±ν•œλ‹€.

@RequiredArgsConstructure - 이 μ• λ„ˆν…Œμ΄μ…˜μ΄ μ§€μ •λœ 클래슀의 λͺ¨λ“  private final ν•„λ“œλ₯Ό μ΄ˆκΈ°ν™”ν•˜λŠ” νŒŒλΌλ―Έν„°λ“€μ΄ ν¬ν•¨λœ μƒμ„±μžλ₯Ό μžλ™ μƒμ„±ν•œλ‹€.

@NoArgsConstructor - μΈμžκ°€ μ—†λŠ” (λ””ν΄νŠΈ) μƒμ„±μžλ₯Ό μžλ™ μƒμ„±ν•œλ‹€.

Last updated