Reputation: 75
In a example like:
@GetMapping(value = "/artists", params = "genre")
public List<Artist> getArtists(@RequestParam String genre) {
}
is including genre
in the params
redundant since it is also declared using @RequestParam
in the method signature ?
When trying to map to different methods for the same URL, is the method signature the one that metters, or is also defining params
necessary?
Upvotes: 1
Views: 426
Reputation: 130977
In the @RequestMapping
annotation (and other HTTP method specific variants), the params
element is meant for narrowing the request mappings based on query parameter conditions. From the documentation:
The parameters of the mapped request, narrowing the primary mapping.
Same format for any environment: a sequence of
myParam=myValue
style expressions, with a request only mapped if each such parameter is found to have the given value. Expressions can be negated by using the!=
operator, as inmyParam!=myValue
.myParam
style expressions are also supported, with such parameters having to be present in the request (allowed to have any value). Finally,!myParam
style expressions indicate that the specified parameter is not supposed to be present in the request.
In the other hand, the @RequestParam
annotation allows you to bind a query parameter to a method argument.
Refer to the documentation for details.
Upvotes: 2