问题
I would like to overload a method with the @QueryParam but everytime I try to execute this code it throws:
SEVERE: Exception occurred when intialization
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
My code is:
@GET
@Path("/test")
@Produces("text/plain")
public String getText(@QueryParam("PID") String pid)
{
return pid;
}
@GET
@Path("/test")
@Produces("text/plain")
public String getText(@QueryParam("PID") String pid, @QueryParam("NAME") String name)
{
return pid + name;
}
回答1:
No can be.
It's ok in java, but the thing about it is - from the servlet side - jersey needs to map each url to some function in your class.
What you can do is, of course, separate it into 2 methods, or build one method that checks the parameters and does the right logic.
回答2:
You can overload the rest endpoint in terms of what request/query parameters are present in the request.
Here's the answer that solved my use case: create two method for same url pattern with different arguments
来源:https://stackoverflow.com/questions/10030045/how-can-i-overload-a-method-with-queryparam-in-jersey-spring