Indicate in the mapping which params should be present
@RequestMapping(method = RequestMethod.GET, params = {"id", "query"})
public A getA(@RequestParam int id, @RequestParam String query) {
...
}
@RequestMapping(method = RequestMethod.GET, params = {"id"})
public A getA(@RequestParam int id) {
...
}
Since Spring MVC version 4.3, the new @GetMapping, @PostMapping, and similar annotations also have this params element you can use
@GetMapping(params = {"id"})
public A getA(@RequestParam int id) {
...
}