BoardApiController
@PostMapping("/api/board/{boardId}/reply")
public ResponseDto<Integer> replySave(@RequestBody ReplySaveRequestDto replySaveRequestDto) {
boardService.댓글쓰기(replySaveRequestDto);
return new ResponseDto<Integer>(HttpStatus.OK.value(), 1);
}
BoardService
@Transactional
public void 댓글쓰기(ReplySaveRequestDto replySaveRequestDto) {
replyRepository.mSave(replySaveRequestDto.getUserId(), replySaveRequestDto.getBoardId(), replySaveRequestDto.getContent());
}
ReplyRepository
public interface ReplyRepository extends JpaRepository<Reply, Integer>{
@Modifying
// ReplySaveRequestDto와 순서를 맞춰야한다.
@Query(value="INSERT INTO reply(userId, boardId, content, createDate) VALUES(?1, ?2, ?3, now())", nativeQuery = true)
int mSave(int userId, int boardId, String content);
}
참고 유튜브 (메타코딩님 강의)
https://youtu.be/FsZLNUJBKOc?si=zg3Bdc3hkGTEMgkk