728x90
CommentSaveRequestDto
public class CommentSaveRequestDto {
private User user;
private Post post;
private String content;
private Comment comment;
public Comment toEntity(User user, Post post) {
return Comment.builder()
.user(user)
.post(post)
.content(content)
.parent(comment)
.build();
}
}
CommentController
@PostMapping("/api/v1/post/{postId}/comment")
public ResponseEntity save(@RequestBody CommentSaveRequestDto dto,
@PathVariable Long postId,
Principal principal) {
Long userId = Long.parseLong(principal.getName());
commentService.save(userId, postId, dto);
return ResponseEntity.ok().body(dto);
}
에러발생
no Creators, like default constructor, exist
해결 방법
빈 생성자 추가
@NoArgsConstructor
public class CommentSaveRequestDto {
private User user;
private Post post;
private String content;
private Comment comment;
public Comment toEntity(User user, Post post) {
return Comment.builder()
.user(user)
.post(post)
.content(content)
.parent(comment)
.build();
}
}
완료!
728x90