79482331

Date: 2025-03-03 23:13:03
Score: 0.5
Natty:
Report link

How can I overload a method with @QueryParam in Jersey/Spring?

This may not be feasible in Jersey, but Spring supports it. Here is your example code modified to work in Spring:

@GetMapping(value = "/test", produces = MediaType.TEXT_PLAIN_VALUE, params = "PID")
public String getText(@RequestParam("PID") String pid) {
    return pid;
}

@GetMapping(value = "/test", produces = MediaType.TEXT_PLAIN_VALUE, params = { "PID", "NAME" })
public String getText(@RequestParam("PID") String pid, @RequestParam("NAME") String name) {
    return pid + name;
}

See also: Overload path functions with different @QueryParams.

Reasons:
  • Blacklisted phrase (0.5): How can I
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @QueryParam
  • Starts with a question (0.5): How can I
  • High reputation (-1):
Posted by: shelley