์ถ์ฒ : ๋ด์ผ๋ฐฐ์์บ ํ
1. Auditing
@CreatedDate
private Date created;
@LastModifiedDate
private Date updated;
@CreatedBy
@ManyToOne // ๊ณ์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ธฐ ๋๋ฌธ์ ์ฐ๊ด๊ด๊ณ๋ฅผ ๋งบ๋๋ค
private Account createdBy;
@LastModifiedBy
@ManyToOne
private Account updatedBy;
์ ์ฉ ๋ฐฉ๋ฒ
1. Applicaton ์๋จ์ @EnableJpaAuditing
2. ์ํฐํฐ(TimeStamped) ํด๋์ค ์์ @EntityListeners(AuditingEntityListener.class) ์ถ๊ฐ
cf) @MappedSuperclass : ํด๋น ํด๋์ค์ ํ๋๊ฐ์ด ์์๋ ๊ฒฝ์ฐ์ ๊ทธ ํ๋ ๊ฐ๋ ์์์ฑ ์ปจํ ์คํธ์ ๊ด๋ฆฌ๋ฅผ ๋ฐ๋ ์์์ฑ ์ํ๊ฐ ๋ ์ ์๋๋ก ๋ง๋ค์ด์ฃผ๋ ์ด๋ ธํ ์ด์
3. AuditorAware ๊ตฌํ์ฒด ๋ง๋ค๊ธฐ :
1) createdAt, ModifiedAt์ ๊ตฌํ์ฒด ์์ด ๋์ํ์ง๋ง, createdBy, modifiedBy๋ ๊ตฌํ์ฒด๊ฐ ํ์ํ๋ค.
2) SpringSecurity์ SecurityContextHolder์์ userDetailsImpl์ ์ฌ์ฉํ์ฌ user ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์์ ๋ฃ์ด์ค๋ค.
4. @EnableJpaAuditing์ AuditorAware ๋น ์ด๋ฆ ์ค์ ํ๊ธฐ
ex : @EnableJpaAuditing(auditorAwareRef = "userAuditorAware")
Auditing์ ํ๋ ๊ฐ์ธ ์์ฑ์ผ์, ์์ฑ์, ์์ ์ผ์, ์์ ์๋ ์ํฐํฐ์ ์์์ฑ์ด ๋ณ๊ฒฝ๋ ๋ ์ ์ฅํ๋ค
Auditing์ ์์ ์ง์ : ์ํฐํฐ ๋ผ์ดํ ์ฌ์ดํด์ธ ์์ฑ, ์์ , ์ญ์ ๋จ๊ณ ์ค ์ธ์ ๋ฉ์๋๋ฅผ ์คํํ ์ง ์ ํ ์ ์๋ค
~ ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ฉด ์๋์ผ๋ก ์คํํ๋๋ก ๋ฉ์๋์ ๋ถ์ด๋ @PostConstruct์ ์๋ฆฌ์ ๊ฐ๋ค
์ํฐํฐ ์์ฑ : @PrePersist, @PostPersist
์ํฐํฐ ์์ : @PreUpdate, @PostUpdate
์ํฐํฐ ์ญ์ : @PreRemove, @PostRemove
2. HATAOAS
์๋ฒ๊ฐ ํด๋ผ์ด์ธํธ์ ํ์ดํผ ๋ฏธ๋์ด๋ฅผ ํตํด ์ ๋ณด๋ฅผ ๋์ ์ผ๋ก ์ ๊ณตํด์ฃผ๋ ๊ฒ
Http ์๋ต์ ๋ค์ด๊ฐ๋ ์์ ๋๋ ๋ค๋ฅธ ์ํ๋ ์์์ ์ ๊ทผํ ์ ์๋ ๋งํฌ๋ฅผ ์ ๊ณตํ๋ค.
์ฌ์ฉ ๋ฐฉ๋ฒ
1) ์์กด์ฑ ์ถ๊ฐ
2) API ๋ฆฌ์์ค์ ๋งํฌ ์ถ๊ฐ
3) ๋งํฌ ๊ณตํตํ : ์ค๋ณต ์ฝ๋๋ฅผ ์ค์ด๊ธฐ ์ํด RepresentationModelAssembler ์ธํฐํ์ด์ค๋ฅผ ์์ํด ์ค๋ณต์ฝ๋๋ฅผ ์ค์ผ ์ ์๋ค
'Spring๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
T ์์นด๋ฐ๋ฏธ : JPA ํ๋ก๊ทธ๋๋ฐ ๊ธฐ์ด (3) (0) | 2023.02.10 |
---|---|
SpringData ์ฟผ๋ฆฌ์ QueryDSL (0) | 2023.02.08 |
SpringData JPA ํ์ด์ง๊ณผ ์ ๋ ฌ (0) | 2023.02.03 |
SpringData ๊ตฌ์กฐ ๋ฐ JpaRepository ์๋ฆฌ (0) | 2023.02.03 |
Raw JPA (0) | 2023.02.02 |