
| νλͺ© | μ€λͺ |
|---|---|
| Entity | DBμ ν μ΄λΈ μν |
| Field | DB μ»¬λΌ μν |
| κΈ°λ³Έ μμ±μ | JPA κ°μ²΄ μμ± μ νμ |
@AllArgsConstructor | @Id @GeneratedValue νλκ° μμΌλ©΄ μ€λ₯ λ°μ |
| Lombok νμ© | @NoArgsConstructor(force = true) + @RequiredArgsConstructor β κΈ°λ³Έ μμ±μ + νμ νλ μμ± |
π‘ Tip: final / @NonNull νλκ° μμ΄λ
force = trueλ₯Ό μ°λ©΄ JPA κΈ°λ³Έ μμ±μλ₯Ό λ§λ€ μ μμ΅λλ€.
| κ΄κ³ | μ€λͺ |
|---|---|
| Owner(1) β Car(N) | ν λͺ μ μμ μκ° μ¬λ¬ λμ μλμ°¨λ₯Ό μμ |
| Car ν΄λμ€ | @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="owner") |
| Owner ν΄λμ€ | @OneToMany(cascade = CascadeType.ALL, mappedBy="owner") |
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@JsonIgnore // cars νλ
Owner β Car κ΄κ³μμ JSON λ³ν μ 무ν 루ν λ°©μ§
create-drop β μ± μ¬μμλ§λ€ ν
μ΄λΈ μ΄κΈ°ν| νλͺ© | μ€λͺ |
|---|---|
| Controller | @RestController + HTTP λ©μλ λ§€ν |
| HTTP λ©μλ | GET β μ‘°ν, POST β μμ±, PATCH/PUT β μμ , DELETE β μμ |
| Repository | JpaRepository ν΅ν΄ DB μ κ·Ό |
| JSON λ³ν | Jackson μλ μ²λ¦¬ |
| Owner β Car | JSON μ§λ ¬ν μ 무ν λ°λ³΅ λ°©μ§ νμ |
/cars, /owners)@RepositoryRestResource(path="vehicles")
HATEOAS μ§μ β JSONμ λ§ν¬ ν¬ν¨
쿼리 λ©μλ μ μ κ°λ₯
/api/cars/search/findByBrand?brand=Kia| νλͺ© | μ€λͺ |
|---|---|
| μμ² μ ν | GET / POST / PATCH / PUT / DELETE |
| PUT vs PATCH | PUT: μ 체 key-value νμ, PATCH: μΌλΆ keyλ§ μμ κ°λ₯ |
| Owner λ±λ‘ | PUT μμ² μ Content-Type = text/uri-list μ€μ νμ |
@ManyToOne / @OneToMany + Fetch μ λ΅