패스 파라미터
url 경로에 / 뒤에 붙게된다
GET /users/123 라면
@GetMapping("/users/{id}")
fun getUser(@PathVariable id: Long): UserResponse {
...
}
물론 여러개를 쓸 수도 있다
/users/{userId}/orders/{orderId}
/shops/{shopId}/products/{productId}
/domains/{domainType}/items/{itemId}
@GetMapping("/users/{username}/{id}")
fun getUserDetail(
@PathVariable username: String,
@PathVariable id: Long
): UserDetailResponse {
...
}
쿼리 파라미터
url 경로에 ? 뒤에 붙는 거
GET /users?age=20&sort=desc 라면
@GetMapping("/users")
fun getUsers(
@RequestParam age: Int?,
@RequestParam sort: String?
): List<UserResponse> {
...
}