// @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 객체가 출력된다 !