JAX-RS (REST)No Comments

In JAX-RS, you can use @QueryParam annotation to inject URI query parameter into Java method. for example,

In above URI pattern, query parameter is “url=javasail.com“, and you can get the url value with @QueryParam(“url”).

  • @QueryParam example

See a full example of using @QueryParam in JAX-RS.

URI Pattern : “users/query?from=100&to=200&orderBy=age&orderBy=name

Like it ?
@QueryParam will convert the query parameter “orderBy=age&orderBy=name” into java.util.Listautomatically.
  • Programmatic Query Parameter

Alternatively, you can get the query parameters grammatically, via “@Context UriInfo“. See equivalent version below :

URI Pattern : “users/query?from=100&to=200&orderBy=age&orderBy=name

  • @DefaultValue example

@DefaultValue is good for optional parameter.

URI Pattern : “users/query

Be the first to post a comment.

Add a comment