๋ฐ์ํ
์ค๊ฐ ์๋ต...
POST ์์ฒญ์ผ๋ก ๋ณด๋ด๋ฉด,,
POST http://localhost:8080/boards/1/pockets
requestBody :
{
"title" : "pocket title"
}
์๋ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
๋์ถฉ ๋ณด๋๊น, PocketController์ addPocket ๋ฉ์๋์ linkTo๋ฅผ ์คํํ๋ค๊ฐ ์๋ฌ๊ฐ ๋ ๊ฒ๊ฐ๋ค.
boardId๊ฐ์ ํ์ฅํ๊ธฐ ์ํ ๋ณ์๊ฐ์ด ์ถฉ๋ถํ์ง ์๋ค..? ๋ผ๊ณ ๋จ๋๋ฐ ๋ญ ๋ง์ด์ง..
@PostMapping
public ResponseEntity addPocket(@PathVariable Long boardId, @RequestBody PocketDto pocketDto) throws NotFoundException {
System.out.println("boardId : " + boardId);
Long id = pocketService.addPocket(boardId, pocketDto);
Pocket pocket = pocketService.findOne(id);
URI uri = linkTo(PocketController.class, boardId).slash(pocket.getId()).withSelfRel().toUri();
return ResponseEntity.created(uri).body(pocket);
}
linkTo ํ๋ผ๋ฏธํฐ์ ์ปจํธ๋กค๋ฌ์ boardId๋ฅผ ํจ๊ป ๋ฃ์ด์ฃผ๋ฉด ํด๊ฒฐ๋๋ค!
๋ฐ์ํ