개발/개발이야기
Springboot JPA kotlin 2. 글 수정, 글 삭제, 글 상세
rCan
2023. 2. 11. 18:00
728x90
반응형
https://github.com/rcaninhu/springboot3-demo
GitHub - rcaninhu/springboot3-demo
Contribute to rcaninhu/springboot3-demo development by creating an account on GitHub.
github.com
지난 게시글에서 수정,
목표 1. 글 상세
목표 2. 글 수정
목표 3. 글 삭제
1. 글 상세.
스프링에 있는 PathVariable를 이용하여 간단하게 상세를.
게시글 아이디를 주면 가져오기.
@GetMapping("/{boardId}")
fun detailBoard(
@PathVariable("boardId") board: Board?
): ResponseEntity<BoardDetailResponse> = board?.let {
ResponseEntity.ok(
BoardDetailResponse(
title = it.title,
contents = it.contents
)
)
} ?: ResponseEntity.noContent().build()
간단하게 글 상세
수정과 삭제를
@PutMapping("/{boardId}")
fun updateBoard(
@PathVariable("boardId") board: Board?,
@RequestBody boardUpdateResponse: BoardUpdateResponse
): ResponseEntity<Void> =
board?.let {
boardService.updateBoard(board, boardUpdateResponse).let {
ResponseEntity.ok().build()
}
} ?: ResponseEntity.noContent().build()
@DeleteMapping("/{boardId}")
fun deleteBoard(
@PathVariable("boardId") board: Board?
): ResponseEntity<Void> =
board?.let {
boardService.softDelete(board).let {
ResponseEntity.ok().build()
}
} ?: ResponseEntity.noContent().build()
2번 글 수정
검색해보면~
어떻게 나올까~
글 삭제.
검색 걸과는 No Content ~~

목표 : #제목 #작성자 #작성일 #조회 게시판
728x90
반응형
SMALL