Answer the question
In order to leave comments, you need to log in
How to check GET parameter name of a request in Sping?
For mapping a GET request, I use the annotation @GetMapping
:
@GetMapping(params = {ParameterName.SORT_BY})
public List<GiftCertificate> findAllSorted(@RequestParam(value = ParameterName.SORT_BY) Set<ColumnName> columnNames) {
return service.findAllSorted(columnNames);
}
ParameterName.SORT_BY
is a regular enum. http://localhost:8080/gift-certificates?sort_by=name
http://localhost:8080/gift-certificates?sort_ABRAKADABRA_by=name
@GetMapping
public List<GiftCertificate> findAll() {
return service.findAll();
}
Answer the question
In order to leave comments, you need to log in
Here is the cat, I gave you the direction to read in the previous question !
Once again - what do the declarations in your code do:
gift-certificates
, as I understand it, this is a global prefix for the controller
@GetMapping(params = {ParameterName.SORT_BY})
means: call this method when the url looks like gift-certificates?sort_by
When the url does not match, the general one is taken - @GetMapping
- which is responsible for gift-certificates
, since all parameters after the question mark are optional .
If you need to somehow catch parameters with arbitrary names - then study this article - typical cases are just analyzed there (in particular, point 6).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question