[b]不翻译了@PathParam is a parameter annotation which allows you to map variable URI path fragments into your method call.[/b]
通过下面的请求,让我们看到参数“param”与参数"many" 对应的@PathParam参数值
[table]
|request|param|many
|/aaabb/some/stuff|bb|some
|/aaab/a/lot/of/stuff|b|a/lot/of
[/table]
[img]http://dl2.iteye.com/upload/attachment/0086/1980/ecae407b-73ca-37c9-90b4-e4b0a31a8873.png[/img]
package com.example.rest.resteasy.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/hello")
public class HelloWorldRestService {
@GET
@Path("{var:.*}/stuff")
public Response getStuff(@PathParam("var") String var) {
String result = "RESTEasy getStuff() is called! pathParam=" + var;
return Response.status(200).entity(result).build();
}
@GET
@Path("/aaa{param:b+}/{many:.*}/stuff")
public Response getIt(@PathParam("param") String bs, @PathParam("many") String many) {
String result = "RESTEasy getIt() is called! pathParam=[param:" + bs + ",many=" + many + "]";
return Response.status(200).entity(result).build();
}
}
通过下面的请求,让我们看到参数“param”与参数"many" 对应的@PathParam参数值
[table]
|request|param|many
|/aaabb/some/stuff|bb|some
|/aaab/a/lot/of/stuff|b|a/lot/of
[/table]
[img]http://dl2.iteye.com/upload/attachment/0086/1980/ecae407b-73ca-37c9-90b4-e4b0a31a8873.png[/img]