Advertisement
Google Ad Slot: content-top
Spring Boot Parameters
Spring Boot provides a simple way to handle Path Parameters and Query Parameters using @PathVariable and @RequestParam.
Path Parameters (@PathVariable)
- Path parameters are part of the URL (e.g.,
/users/{id}). - They are mandatory.
- Used to identify a specific resource.
Query Parameters (@RequestParam)
- Query parameters are appended after
?in the URL (e.g.,/users?name=Alice). - They are optional (can have default values).
- Used for searching, filtering, sorting.
Multiple Query Parameters
- You can pass multiple parameters using
@RequestParam.
Combining Path & Query Parameters
You can use both @PathVariable and @RequestParam together.
Set default values "Unknown" if parameter doesn't have city http://localhost:8080/api/user/10/details