hrming

@PathVariable / @RequestParam과 @PathVariable의 차이점 본문

REST API

@PathVariable / @RequestParam과 @PathVariable의 차이점

hrming 2022. 11. 24. 22:45

@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: 

https://www.digitalocean.com/community/tutorials/spring-requestmapping-requestparam-pathvariable-example

 

Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable | Digital

 

www.digitalocean.com

 

참고/출처3: 

https://velog.io/@dmchoi224/Rest-API-RequestParam-%EA%B3%BC-PathVariable#requestparam-%EA%B3%BC-pathvariable

 

Rest API , @RequestParam 과 @PathVariable

REST API REST API 란 REST API 에서 REST는 Representational State Transfer 의 약자로 소프트웨어 프로그램 아키텍처의 한 형식. 즉, 자원을 이름 (자원의 표현) 으로 구분하여 해당 자원의 상태 (정보)를 주고 받

velog.io

 

Comments