http://localhost:8080/books/: 책 전체 목록을 요청http://localhost:8080/books/1: id:1번 책을 요청http://localhost:8080/books/123: id:123번 책을 요청@RestController
public class HelloWorldController {
@GetMapping(path = "/hello-world-bean/path-variable/{name}")
public HelloWorldBean helloWorldBean(@PathVariable String name) {
return new HelloWorldBean(String.format("Hello World, %s", name));
}
}
@PathVariable을 ArgumentResolver가 인식하여 URL 경로 중의 {name}와 매개변수의 name을 매치시켜 줄 것이다.
문자열의
+연산 대신에,String.format()메소드를 사용했다.
위와 같은 예제 메소드를 추가하고 이에 따른 결과를 확인해보자.

위와 같은 결과가 출력된다.