Difference between JAX-RS @QueryParam and @MatrixParam

Asked on June 05, 2016
What is difference between JAX-RS @QueryParam and @MatrixParam?

Replied on June 05, 2016
JAX-RS uses @QueryParam to access query string and @MatrixParam to aceess matrix parameter.
@QueryParam
Find the URL
/test/data?id=123&name=Ram
Find the code to access query string using @QueryParam
@Path("/data/{id}/{name}")
@Produces("text/plain")
public String add(@QueryParam("id") Integer id, @QueryParam("name") String name ){
//ToDo
return "result";
}
For more detail, find the URL.
@MatrixParam
Find the matrix URI
/application/employee/detail;name=mohan;age=37
Find the code to access matrix parameter
@GET
@Path("/detail")
@Produces("application/json")
@Formatted
public Response detail(@MatrixParam("name") String name, @MatrixParam("age") String age) {
Map<String,String> map = new HashMap<String,String>();
map.put("name", name);
map.put("age", age);
return Response.ok(map).build();
}
For more detail, find the URL.