record 타입은 기본적으로 private final이기 때문에 접근 제어자 생략 가능
record는 @Getter 사용 안함
변경 전
@Getter
public class PostResponseDto (
private Long id;
private String title;
private String author;
private String content;
)
public PostResponseDto(PostEntity savePost) {
this.id = savePost.getId();
this.title = savePost.getTitle();
this.author = savePost.getAuthor();
this.content = savePost.getContents();
}
}
package com.sparta.springtodo.dto;
import com.sparta.springtodo.entity.PostEntity;
import lombok.Getter;
import java.time.LocalDateTime;
public record PostResponseDto (
Long id,
String title,
String author,
String content
)
public PostResponseDto(PostEntity savePost) {
this(
savePost.getId(),
savePost.getTitle(),
savePost.getAuthor(),
savePost.getContents()
);
}
}