// @PathVariable์ ํ์ฉํ GET ์์ฒญ
// http://localhost8090/api/v1/:bookName
@GetMapping("/{bookName}")
public String getBookWithName(@PathVariable String bookName){
return bookName;
}
์ฝ๋ ์ถ๊ฐ
[๊ฒฐ๊ณผ]
์๋ฒ ๊ป๋ค๊ฐ(ctrl+c
) ๋ค์ ํจ ํ,
http://localhost:8090/api/v1/๊น๋นต๋นต์๋๊ตฌ์ธ๊ฐ
์
๋ ฅ, Send
ํด๋ฆญ
Response์ ๊น๋นต๋นต์๋๊ตฌ์ธ๊ฐ
์ถ๋ ฅ๋๋ค !
// DTO(Data Transfer Object) ๊ฐ์ฒด ๋ฐํํ๋ GET ์์ฒญ
// http://localhost:8090/api/v1/book/dto?name=์ฑ
์ด๋ฆ&author=์ ์
@GetMapping("/book/dto")
public BookDto getBookDto(BookDto bookDto){
return bookDto;
}
์ฝ๋ ์ถ๊ฐ
rest - ํด๋ ๋ช
: model
์ถ๊ฐ
model - ํ์ผ ๋ช
: BookDto.java
์์ฑ
private์ผ๋ก name
, author
๋ณ์ ์ ์ธ
์ฐํด๋ฆญ - ์์ค ์์
ํด๋ฆญ
Generate Getters and Setters
ํด๋ฆญ
name, author ํด๋ฆญ ํ ํ์ธ
Getter, Setter๊ฐ ์์ฑ๋์๋ค!
[๊ฒฐ๊ณผ]
์๋ฒ ๊ป๋ค๊ฐ(ctrl+c
) ๋ค์ ํจ ํ,
http://localhost:8090/api/v1/book/dto?name=๊ฐ๋ฏธ&author=๋ฒ ๋ฅด๋ฒ ๋ฅด
์
๋ ฅ ํ, Send
ํด๋ฆญ
Body ๋ถ๋ถ์ DTO ๊ฐ์ฒด๊ฐ ์ถ๋ ฅ๋๋ค !