Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

java - Is it possible to configure JAX-RS method with variable number of URI parameters?

is it possible to configure GET method to read variable number of URI parameters and interpret them either as variable argument (array) or collection? I know query parameters can be read as list/set but I can't go for them in my case.

E.g.:

@GET
@Produces("text/xml")
@Path("list/{taskId}")
public String getTaskCheckLists(@PathParam("taskId") int... taskId) {
    return Arrays.toString(taskId);
}

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I understand your question correctly, the @Path annotation can take a regular expression to specify a list of path components. For example, something like:

@GET
@Path("/list/{taskid:.+}")
public String getTaskCheckLists(@PathParam("taskid") List<PathSegment> taskIdList) {
    ......
}

There's a more extensive example here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...