JAX-RS (REST)No Comments

In JAX-RS, you can use @Path to bind URI pattern to a Java method. See following examples to show you how it works.

  • Normal URI Matching

See normal URI matching with @Path annotation.

URI pattern : “/users

URI pattern : “/users/vip

  • URI Matching and Parameter

The value within an open brace “{” and close brace “}”, is represents a parameter, and can be access with @PathParam.

URI Pattern : “/users/javasail

URI Pattern : “/users/abcdefg

  • URI Matching and Regular Expression

@Path support complex URI matching with regular expression, via following expression :

URI Pattern : “/users/999

URI Pattern : “/users/123456

 

URI Pattern : “/users/username/aaa” , failed, don’t match “[a-zA-Z][a-zA-Z_0-9]”, first character need “[a-zA-Z]”, second character need “[a-zA-Z_0-9]”.

URI Pattern : “/users/username/a9

URI Pattern : “users/books/999


Be the first to post a comment.

Add a comment