Is there a way to use this parameter style:
/products/123;456;789
in JAX-RS with Jersey? If I use PathParam, only the first para
When you use semicolon, you create Matrix parameters.
You can use either @MatrixParam
or PathSegment
to get them. Example:
public String get(@PathParam("param") PathSegment pathSegment)
Pay attention that Matrix parameters are these that follow the original parameter. So in case of "123;456;789" - 123 is path parameter, while 456 and 789 are the names of matrix parameters.
So if you want to get products by ids, you can do something like this:
public List<Product> getClichedMessage(@PathParam("ids") PathSegment pathSegment) {
Set<String> ids = pathSegment.getMatrixParameters().keySet();
// continue coding
}
Pay attention that your url should be /products/ids;123;456;789
Actually, IMO it is not a very good design: you use matrix parameter name as a value. I think using query parameters is better: /products?id=123&id=456&id=789
, so you can easily get them in method:
public List<Product> getClichedMessage(@QueryParam("id") List<String> ids)