필요한 정보
board id, title, content
dto
@Data
public static class DTO {
private int id;
private String title;
private String content;
public DTO(Board board) {
this.id = board.getId();
this.title = board.getTitle();
this.content = board.getContent();
}
}
컨트롤러
@GetMapping("/api/boards/{id}")
public ResponseEntity<?> findOne(@PathVariable Integer id) {
BoardResponse.DTO respDTO = boardService.updateForm(id);
return ResponseEntity.ok(new ApiUtil(respDTO));
}
서비스
// 글 수정 조회
public BoardResponse.DTO updateForm(Integer boardId) {
// 조회 및 예외처리
Board board = boardJAPRepository.findById(boardId)
.orElseThrow(() -> new Exception404("게시글을 찾을 수 없습니다."));
return new BoardResponse.DTO(board);
}