RESTEasy @PathParam 与正则表达式映射
不翻译了@PathParam is a parameter annotation which allows you to map variable URI path fragments into your method call.
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参数值
|request|param|many |/aaabb/some/stuff|bb|some |/aaab/a/lot/of/stuff|b|a/lot/of
