Overload Controller Method in Java Spring

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) {
    ...
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)