如何提供 PathParm - jax-rs

How to provide PathParm - jax-rs

如何将变量传递给以下方法

@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";
    }
}

以下 URL 为我提供了参数的空输出

http://localhost:8080/entry-point/test/ = 嗨 null http://localhost:8080/entry-point/test/value = 404 错误

谢谢

您必须路由请求。因此,例如,如果我想访问测试方法,这就是我需要做的路由

http://localhost:8080/entry-point/test/thisIsTheStringPARAM 

The 'thisIsTheStringPARAM' part of the url is been retrieved by '@PathParam("param")' and assigned to the 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";
    }
}