Search

9. 스프링부트 Controller 쿼리스트링, 주소변수매핑

http 쿼리 스트링(querystring), 주소 변수 매핑(path variable)

생성

1. 구체적인 데이터 요청시에 쿼리스트링이나 주소변수매핑이 필요하다.

package com.cos.controllerdemo.web; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @RestController public class QueryPathController { @GetMapping("/chicken") public String chickenQuery(String type) { return type + "배달갑니다. (쿼리스트링)"; } @GetMapping("/chicken/{type}") public String chickenPath(@PathVariable String type) { return type + "배달갑니다.(주소변경매핑)"; } }
Java
복사

2. 스프링부트에서는 주소변수매핑을 주로 사용한다. 훨씬 편리하다.

null로 뜬다 그러면 주소에 이제
주소변경매핑이 스프링부트에서 자주 사용하고 가독성에도 좋고 훨씬 편하다.

*참고