JAX-RS @MatrixParam example

This post is in continuation with web service tutorial (Part -10).

In previous post, we have used @QueryParam for passing parameter to URL in JAX-RS @QueryParam example and  In case of @QueryParam, we pass parameters as well as its values separated by ? but in case of @MatrixParam, key value pairs are separared by semicolon(;).
For example:

Here Parameter names are id,countryName and its values are 3,Nepal respectively separated by ;.

Here are steps to create a JAXRS json example which will use @MatrixParam.

1) Follow steps on RESTful Web Services json example to create simple RESTful web services which uses @PathParam.
2) Change CountryRestService.java to use @MatrixParam as below.

That’s all. We need to run the application now.

Run the application

3) Right click on project -> run as -> run on server
Select apache tomcat and click on finish
4) Now pass country id and country name as parameters to url separated by ;.

We are done with Restful web services json MatrixParam example. If you are still facing any issue, please comment.

Join Our Newsletter

Subscribe to Awesome Java Content

Add Comment

Join Our Newsletter

Subscribe to Awesome Java Content