Reputation: 410
I want to pass an optional parameter in the JAX-RS path.I am using the below path but its not working.
@Path("/lock/{userName}/{userid:(([a-zA-Z]{2})?)}")
The resource should get invoked for both with userid and without user id parameter in the path. Can anyone suggest me what needs to be done?
Thanks
Upvotes: 3
Views: 1821
Reputation: 1
It's also possible to use FormParam instead of PathParam
@POST
@Path("/lock/{userName}")
public Response resourceName(@PathParam("userName") String userName, @FormParam("userId") String userId)
You can provide the userId or not.
Upvotes: 0
Reputation: 209092
You could take out the /
between the two template parameters and insert it into the regex of the userId
@Path("/lock/{userName}{userid:((/[a-zA-Z]{2})?)}")
Won't make a difference, but the extra wrapping parenthesis are not needed,
i.e. this {userid: (/[a-zA-Z]{2})?}
is sufficient
Upvotes: 2