Irshad
Irshad

Reputation: 1114

jax-rs: jersey @pathparam to get previous param in one method

How would i get the last path parameter in on method.

@Path("{profile}/articles")
 public getAllArticles(@PathParam("profile") String profile ){

}
@Path("{articleId}")
 public getArticle(@PathParam("articleid") long id ){

}

I know how to get the recent path parameter like articleId in method getArticle. but i want to get the previous path parameter in the getArticle method.

ex: if the URL is /{profile}/articles/{articleId}. How would I get values of both {profile} and {articleId} in same method

PS: I know i can get that by breaking the URL,if I get path from UriInfo

Upvotes: 0

Views: 231

Answers (1)

Jin Kwon
Jin Kwon

Reputation: 22027

You can get multiple @PathParam if you specified in the @Path annotation.

@Path("/{profile}/articles/{articleId: \\d+}")
public Article readArticle(
    @PathParam("profile") final String profile,
    @PathParam("articleId") final long articleId) {

    // "SELECT a FROM Article a WHERE a.profile=:profile AND a.id=:aid"
}

I wish I can include any further explanation.

Upvotes: 1

Related Questions