Java – resteasy @ path with zero or more path parameters
•
Java
I use resteasy. Com in API development My website is http: / / localhost: 8080 / project / player / m or http: / / localhost: 8080 / project / player
This means that I treat {gender} as a path parameter
My problem is how to map this URL to the rest method. I use the following mapping
@GET @Path("player/{gender}") @Produces("application/json")
But if you use it, it maps to http: / / localhost: 8080 / project / player / m, but not to http: / / localhost: 8080 / project / player I need a regular expression to map zero or more path parameters
thank you.
Solution
The path parameter (@ pathparam) is not optional If you want a map;
> http://localhost:8080/project/player/M > http://localhost:8080/project/player
You will need two methods You can use method overloading;
@GET @Path("player/{gender}") @Produces("application/json") public Whatever myMethod(@PathParam("gender") final String gender) { // your implementation here } @GET @Path("player") @Produces("application/json") public Whatever myMethod() { return myMethod(null); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码