0

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

Irshad
  • 1,016
  • 11
  • 30

1 Answers1

1

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.

Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – gunr2171 Sep 17 '15 at 14:42