I'm playing around with Jersey 2.21
and I'd like to know if it's possible to have an "optional" param which can, or not, be present in the request made to the server.
I want to successfully access this two methods:
http://localhost:8080/my_domain/rest/api/myMethod/1
http://localhost:8080/my_domain/rest/api/myMethod
As you can see, I'm trying to make the integer (id
) param an optional one.
I've declared myMethod
as follows:
@GET
@Path("myMethod/{id}")
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
public String myMethod(@PathParam("id") Integer id, @Context HttpHeaders hh)
This works:
http://localhost:8080/my_domain/rest/api/myMethod/1
and this works too:
http://localhost:8080/my_domain/rest/api/myMethod/
but this won't work and I don't understand why. It throws a 404 Not Found
error:
http://localhost:8080/my_domain/rest/api/myMethod
Can you point me in the right direction to work this out? I don't like the slash being mandatory on all my REST method calls and would like to suppress it if possible.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…