앞서 유저 조회처럼 page를 사용하여 조회하는 코드를 작성
@ApiOperation(value = "게시물 조회")
@GetMapping("/post/{id}")
public Board BoardDetail(@PathVariable int id,Board board){
board.setCount(board.getCount()+1);
return boardRepository.findById(id).orElseThrow(()->
new RuntimeException("게시물이 존재하지 않습니다."));
}
@ApiOperation(value = "게시물 삭제")
@DeleteMapping("/post/{id}")
public String deletPost(@PathVariable int id){
try {
boardRepository.deleteById(id);
}catch (Exception e){
return "해당 게시물은 존재하지 않습니다";
}
return "게시물이 삭제되었습니다.";
}
@ApiOperation(value = "게시물 수정")
@Transactional
@PutMapping("/updatepost/{id}")
public Board updatePost(@PathVariable int id, @RequestBody Board reqBoard){
Board board = boardRepository.findById(id).orElseThrow(()->{
return new RuntimeException("해당 게시물이 존재하지 않습니다.");
});
board.setTitle(reqBoard.getTitle());
board.setContent(reqBoard.getContent());
return board;
}