Thursday, November 15, 2018

JAX-RS @MatrixParam Example

@MatrixParam Binds the value(s) of a URI matrix parameter to a resource method parameter, resource class field, or resource class bean property.

Matrix parameters are a set of “name=value” in URI path, for example,

/contacts/888;email=188@i88.ca;firstname=superman;lastname=Doe;

888 is @PathParam

You can use
myMethod(@PathParam("id") String id,  @MatrixParam("email") String email,  @MatrixParam("firstname") String firstname,  @MatrixParam("lastname") String lastname)

The order of @MatrixParam doesn't matter:  lastname can be put before email etc.

Not all fields are necessary, some fields can be miss, for example, you may only have email and firstname, without lastname:

/contacts/888;email=188@i88.ca;firstname=superman