hrming
@PathVariable / @RequestParam과 @PathVariable의 차이점 본문
@PathVariable
: 경로의 특정 위치 값이 고정되지 않고 달라질 때 사용
: We can even specify Regular Expression for URI dynamic parameter to accept only specific type of input. It works with @PathVariable annotation through which we can map the URI variable to one of the method arguments
@RequestMapping(value="/method7/{id}")
@ResponseBody
public String method7(@PathVariable("id") int id){
return "method7 with id="+id;
}
@RequestParam과 @PathVariable의 차이점
- @RequestParam 과 @PathVariable은 둘 다 데이터를 받아오는 데에 사용한다.
- @PathVariable은 값을 하나만 받아올 수 있으므로, 쿼리스트링 등을 이용한 여러 개 데이터를 받아올 때는 @RequestParam을 쓴다
- @PathVariable은 최소한의 변경으로 여러곳에서 재사용
참고/출처1:
https://kkangdda.tistory.com/36
RESTful(1) - @PathVariable 사용하기
@PathVariable → URL경로에 변수 넣어주기 = RESTful 서비스의 URL형태 사용방법: @RequestMapping의 URL 정의 & Method내의 파라미터 부분의 정의 → @RequestMapping 어노테이션 값으로 {템플릿변수} 를 사용 → @Pat
kkangdda.tistory.com
참고/출처2:
Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable | Digital
www.digitalocean.com
참고/출처3:
Rest API , @RequestParam 과 @PathVariable
REST API REST API 란 REST API 에서 REST는 Representational State Transfer 의 약자로 소프트웨어 프로그램 아키텍처의 한 형식. 즉, 자원을 이름 (자원의 표현) 으로 구분하여 해당 자원의 상태 (정보)를 주고 받
velog.io
'REST API' 카테고리의 다른 글
REST API와 RESTful API의 차이점 (0) | 2022.11.24 |
---|---|
[REST API] GET, POST, PUT, DELETE (PUT과 POST 차이/PUT과 PATCH 차이) (0) | 2022.11.10 |