The client may request two urls with the same path but different query strings:
1. /hello
2. /hello?name=Mike
How to use jersey to define two different methods for each of them?
Here is an example:
@Path("/hello")
public class HelloResource {
@Produces("text/plain")
public String justHello() {}
// how to call this method only the query string has "name"
@Produces("text/plain")
public String helloWithName() {}
}
You can’t do this, Jersey only matches the path. See http://jersey.java.net/nonav/documentation/latest/jax-rs.html for full details.
You can build your own switch based on the query parameter being present. In general, name=mike is not very RESTy anyways. Jersey does support:
And that’s the way it’s meant to be used.