πŸ“¦ DTO κ΅¬ν˜„ κ΄€λ ¨ 정리 (Request / Response)

βœ… κ΅¬ν˜„ν•˜λ©΄μ„œ λŠλ‚€ 점


πŸ”„ RequestDto와 ResponseDto 차이점

ꡬ뢄 λͺ©μ  μ‚¬μš©ν•˜λŠ” μ• λ„ˆν…Œμ΄μ…˜ 이유
RequestDto πŸ’¬ ν΄λΌμ΄μ–ΈνŠΈ β†’ μ„œλ²„ μ‚¬μš©μžκ°€ μž…λ ₯ν•œ 데이터 λ°›κΈ° @Getter, @Setter μ‚¬μš©μžμ˜ μš”μ²­ 데이터λ₯Ό λ°›μ•„μ„œ μ²˜λ¦¬ν•΄μ•Ό ν•˜λ―€λ‘œ ν•„λ“œ μˆ˜μ • κ°€λŠ₯ν•΄μ•Ό 함
ResponseDto πŸ“¦ μ„œλ²„ β†’ ν΄λΌμ΄μ–ΈνŠΈ μ„œλ²„κ°€ ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ 응닡할 데이터 전달 @Getter만 μ‚¬μš© 응닡 λ°μ΄ν„°λŠ” 읽기 μ „μš©μœΌλ‘œ μ „λ‹¬ν•˜λ―€λ‘œ μˆ˜μ •ν•  ν•„μš” μ—†μŒ

πŸ’‘ μΆ”κ°€ 팁


// ResponseDto μ˜ˆμ‹œ
@Getter
public class DiaryResponseDto {
    private Long id;
    private String title;
    private String content;

    public DiaryResponseDto(Diary diary) {
        this.id = diary.getId();
        this.title = diary.getTitle();
        this.content = diary.getContent();
    }
}


🧠 μš”μ•½

ν•­λͺ© RequestDto ResponseDto
μ‚¬μš©ν•˜λŠ” κ³³ ν΄λΌμ΄μ–ΈνŠΈ β†’ μ„œλ²„ μ„œλ²„ β†’ ν΄λΌμ΄μ–ΈνŠΈ
μ—­ν•  μ‚¬μš©μž μž…λ ₯ λ°›κΈ° 응닡 데이터 전달
μ• λ„ˆν…Œμ΄μ…˜ @Getter, @Setter @Getter만
ν•„λ“œ λ³€κ²½ κ°€λŠ₯ν•΄μ•Ό 함 λΆˆν•„μš” (읽기 μ „μš©)