Answer the question
In order to leave comments, you need to log in
Why doesn't a GET request hit a @GetMapping annotated method with parameters in Spring?
There is a method in the controller that handles the GET request. This method is annotated
@GetMapping(params = {ParameterName.SORT_BY, ParameterName.SORT_TYPE})
. This method in the arguments with the help of an annotation @RequestParam
binds the argument that came from the GET request to a Java variable of the String type. It looks like this:@GetMapping(params = {ParameterName.SORT_BY, ParameterName.SORT_TYPE})
public List<GiftCertificate> findAllAndSort(@RequestParam(value = ParameterName.SORT_BY) String sortBy,
@RequestParam(value = ParameterName.SORT_TYPE, required = false) String sortType) {
log.info("Sorting: {}, {}", sortBy, sortType);
return service.findAllAndSort(sortType, sortBy);
}
@RequestParam(value = ParameterName.SORT_TYPE, required = false) String sortType).
http://localhost:8080/gift-certificates?sort_by=name&sort_type=DESC
http://localhost:8080/gift-certificates?sort_by=name
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question