如何将变量传递给以下方法
@Path("/entry-point")
public class EntryPoint
{
private final Logger logger = Logger.getLogger(EntryPoint.class);
@GET
@Path("test")
public Response test(@PathParam("param") String param)
{
logger.info("Received message " + param);
String output = "Hi : " + param;
return Response.status(200).entity(output).build();
}
@GET
@Path("/{test2}")
public String test2(@PathParam("param") String param)
{
logger.info("Received message " + param);
return "yo";
}
}
以下网址为参数
提供了空输出http://localhost:8080/entry-point/test/ = hi null http://localhost:8080/entry-point/test/value = 404错误
感谢
答案 0 :(得分:0)
您必须路由请求。因此,例如,如果我想要达到测试方法,这就是我需要做的路由
http://localhost:8080/entry-point/test/thisIsTheStringPARAM
网址的'thisIsTheStringPARAM'部分已被检索 '@PathParam(“param”)'并分配给String param。
查看下面的代码我也做了一些更改。
@Path("/entry-point")
public class EntryPoint
{
private final Logger logger = Logger.getLogger(EntryPoint.class);
@GET
@Path("/test/{param}")
public Response test(@PathParam("param") String param)
{
logger.info("Received message " + param);
String output = "Hi : " + param;
return Response.status(200).entity(output).build();
}
@GET
@Path("/test2/{param}")
public String test2(@PathParam("param") String param)
{
logger.info("Received message " + param);
return "yo";
}
}