-
[Spring Boot] What are query parameter and @RequestParam Annotation?ComputerScience/Spring Boot 2022. 3. 8. 21:26
1. What is API query parameter.
API query parameter은 URL 의 '?' 마크 뒤의 optional key-value pairs로 정의된다.
브라우저 링크에서 다음과 같은 링크를 자주 보곤 한다.
https://a.com/api/get/users?id=1&name=lee
URL 맨 마지막 '?' 표시 뒤 값을 query string이라고 한다.
URL 맨 마지막 '?'표시 뒤 key-value pair 형식의 값을 우리는 query parameter라고 부른다.
'?' 마크는 url의 path와 query parameter를 분리하기 위해 사용된다.
'&' 마크는 2개 이상의 parameter를 표시하기 위해 사용된다.
2. What is @RequestParam Annotation.
@RequestParam Annotation은 query parameter를 전달 받을 때 사용된다.
@GetMapping("/get-mapping/query-param")// ?name=lee&age=20 fun queryParam( @RequestParam name : String, @RequestParam age:Int ):String{ return name+" "+age }
path/get-mapping/query-param?name=Lee&age=20 을 브라우저에 입력하면
{"name" : "Lee" , "age" : "20"}과 같이 표시된다.
'ComputerScience > Spring Boot' 카테고리의 다른 글
[Spring Boot로 TodoList 만들기] 1. 목표 (1) 2022.03.26 [Spring Boot] application.properties (0) 2020.07.12