java / beginner
Snippet
Filtering Results with @RequestParam
@RequestParam allows you to access query parameters from the URL (e.g., /search?query=java). You can also provide default values.
snippet.java
1
2
3
4
@GetMapping("/search")public List<Item> search(@RequestParam(defaultValue = "none") String query) {return itemService.findByName(query);}
spring
Breakdown
1
@RequestParam(defaultValue = "none")
Specifies a query parameter. If not provided in the URL, 'none' is used as the default.
2
String query
The variable that holds the value of the 'query' parameter from the URL.