Inflearn Community Q&A
@GetMapping(
Written on
·
366
0
@GetMapping("/{itemId}")
public String item(@PathVariable long itemId,Model model){
Item item = itemRepository.findById(itemId);
model.addAttribute("item",item);
return "/basic/item";
}
@GetMapping("/{itemId}")
이 부분에서 /basic/items/{itemId} url을 입력하였을때
{itemId} 이 부분이 그대로 입력되지않고 치환이 일어나는
과정이 궁금합니다. {} 이것을 붙여서 치환되는 건가요 ?.
Quiz
When creating dynamic web pages with Spring MVC, what are the key dependency combinations needed for basic web features and HTML template processing? The key dependencies typically include: * `spring-boot-starter-web` (for core web capabilities) * A template engine starter like `spring-boot-starter-thymeleaf` (for HTML templating)
Web, H2
Web, Thymeleaf
JPA, Lombok
Test, Web
Answer 2
5
안녕하세요. qheogus55님, 공식 서포터즈 David입니다.
.
내부적으로 요청된 URL과 맵핑된 URL을 각각 비교합니다.
요청된 URL(ex. /items/777)과 맵핑된 URL(ex. /items/{id})을 "/"을 기준으로 자릅니다.
요청된 URL의 tokens(items, 777), 맵핑된 URL의 tokens(items, {id})을 가지고 패턴매칭을 진행합니다.
패턴이 매칭된다면 매칭된 맵핑({GET /items/{id})을 기준으로 핸들러 메서드를 가져옵니다.
패턴매칭할 때는 AntPathMatcher클래스가 사용됩니다.
아래 이미지는 패턴매칭이 진행중인 코드입니다.
.
감사합니다.
0




