Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 15
Path Variables & Request Params
Two ways data flows into a controller: path variables identify a resource (/orders/42), query params filter or paginate (?status=PAID&page=1).
Course progress0%
Focus
3 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Two ways data flows into a controller: path variables identify a resource (/orders/42), query params filter or paginate (?status=PAID&page=1).
Informative example
ts
@GetMapping("/users/{userId}/orders/{orderId}")public OrderDto get(@PathVariable Long userId,@PathVariable Long orderId) { ... }@GetMapping("/orders")public Page<OrderDto> search(@RequestParam(required = false) OrderStatus status,@RequestParam(defaultValue = "0") int page,@RequestParam(defaultValue = "20") @Max(100) int size) { ... }
Best practices
- Use path vars for identity; query params for filtering/sorting/paging.
- Bound page size with
@Max— unbounded pages OOM your DB. - Default everything sensibly; clients should be able to call
/orderswith no params.
Ready to mark this lesson complete?Track your journey across the entire course.