Programming
[Spring] @PathVariable을 이용한 경로(@RequestMapping) 변수
상상쓰
2021. 8. 26. 15:55
@ReqeustMapping(value = "/Contents/{id}.do")
public String getPage(@PathVariable String id, HttpServletReqeust request, ModelMap model) throws Exception {
System.out.println(id); // https://localhost/Contents/01.do > id = "01"
return "page/01";
}
@ReqeustMapping(value = "/Contents{id}.do")
public String getPage(@PathVariable String id, HttpServletReqeust request, ModelMap model) throws Exception {
System.out.println(id); // https://localhost/Contents01.do > id = "01"
return "page/01";
}
변수의 값은 파라미터의 타입에 맞게 변환해준다. (@PathVariable int id 로 설정하였는데 {id} 가 "string" 이라면 400 error)
@PathVariable 을 이용한 변수는 두 개 이상 사용할 수도 있다.