6/05/2011
6/03/2011
Spring3에서 @RequestMapping시 URI tempate이 제대로 먹히지 않는 경우
The URI Template "@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET) public String findOwner(@PathVariable String ownerId, Model model) { Owner owner = ownerService.findOwner(ownerId); model.addAttribute("owner", owner); return "displayOwner"; }
/owners/{ownerId}
" specifies the variable name ownerId. When the controller handles this request, the value of ownerId is set to the value in the request URI. For example, when a request comes in for /owners/fred, the value fred is bound to the method parameter String ownerId
.The matching of method parameter names to URI Template variable names can only be done if your code is compiled with debugging enabled. If you do not have debugging enabled, you must specify the name of the URI Template variable name in the @PathVariable annotation in order to bind the resolved value of the variable name to a method parameter.
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html
요약 : Spring3에서 아래와 같이 작성을 해주면 /owners/1234 와 같이 URL이 GET으로 호출되는 경우 String ownerId 에 1234 라는 값이 자동으로 저장된다. 하지만 이건 debug enabled로 컴파일 되었을 때의 경우이고(디버깅용으로 생성된 정보를 이용해서 매칭해 준다는 거지), 제대로 하려면 @PathVariable("ownerId") 처럼 해줘야 한다는 것. 이 경우 실제 변수명은 꼭 ownerId가 아니어도 상관없다.(당연) 즉, String ownerId 이든 String theOwner이든 앞에 @PathVariable("ownerId") 만 URI tempate의 것과 맞으면 값을 할당됨.
은근히 처음 방법으로 코딩해 놓은 것들을 많이 찾아볼 수 있는데, 항상 디버깅 정보를 넣은 채로 컴파일이 되는 건 아니니까 항상 이름을 명시해주는 방식으로 코딩하자.
-P.S-
그러고보니 이 블로그에 이런 내용을 쓰는건 진짜 백만년만인듯...
피드 구독하기:
글 (Atom)
요즘 포스팅을 모두 medium쪽으로 하고 있습니다
안녕하세요? 어쩌다보니 그냥 한번 써보기로 한 medium.com 에다가 죄다 최근 포스팅을 하고 있습니다. 현재 도메인인 potatosoft.com 은 제가 대학때인가 사회 취업한지 얼마 안됐을때부터 유지해 온 도메인이고, 블로그 시스템은 그...
-
현재 경부고속도로 버스전용차선이 평일은 오전 7시부터 오후 9시까지, 토/공휴일은 오전 9시부터 오후 9시까지인가 운영되고 있는걸로 알고 있습니다만, 2011년 1월 1일부터 이게 바뀌어서 평일/주말 할 것 없이 오전 7시부터 오후 9시까지 운영됩니다...
-
아래 내용은 제가 올해 3월에 한국에서 미국 캘리포니아로 이사하면서 만들었던 체크리스트를 약간 손 본 겁니다. 원래는 같이 옮겨오던 직장 동료들과 만들었던 까페에 올렸던 건데 대부분 이사를 완료한 관계로 까페를 폐쇄 예정이라 정보저장/공유를 위해 가...
-
오랜만에 포스팅하는 글이 영어 관련 쓸데없는 뻘글이라 좀 그렇지만, 페이스북에 적기 시작한 글이 너무 길어져서 블로그에 포스팅하기로 함. 미국에 2011년에 넘어왔으니까 올해로써 이제 미국생활 4년차 들어간다. 처음에 왔을때는 4년정도 여기 있으...