You can use the @RequestParam
annotation on method parameters
@RequestMapping (...)
public String getBooks(@RequestParam(required = false, value = "sortby") String sortBy, @RequestParam(required = false, value = "year") String year) {...}
The @RequestParam
annotation also has a defaultValue
attribute to use as a value if the request parameter isn't provided. Without it, if the parameter is not provided, null
will be passed as the argument for that parameter.