Java jersey@PathParam:如何传递包含多个斜杠的变量

Java jersey@PathParam:如何传递包含多个斜杠的变量,java,rest,jersey,jax-rs,jersey-client,Java,Rest,Jersey,Jax Rs,Jersey Client,在web.xml中,我将URL模式指定为/rest/*,在RestServicePathParamJava4s.java中,我们将类级@Path指定为/customers,方法级@Path指定为{name}/{country} 所以最终的URL应该是 package com.java4s; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produc

在web.xml中,我将URL模式指定为
/rest/*
,在
RestServicePathParamJava4s.java
中,我们将类级
@Path
指定为
/customers
,方法级
@Path
指定为
{name}/{country}

所以最终的URL应该是

package com.java4s;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@Path("/customers")
public class RestServicePathParamJava4s {
    @GET
    @Path("{name}/{country}")
    @Produces("text/html")
    public Response getResultByPassingValue(
                @PathParam("name") String name,
                @PathParam("country") String country) {

        String output = "Customer name - "+name+", Country - "+country+"";
        return Response.status(200).entity(output).build();

    }
}
并且响应应显示为

http://localhost:2013/RestPathParamAnnotationExample/rest/customers/Java4/USA
如果我给出下面给出的2个输入,则表明存在错误。如何解决这个问题

Customer name - Java4, Country - USA

这里
Java4:kum77./@.com
这是一个字符串,包含正斜杠。如何通过使用
@PathParam
或任何我需要使用的
多值dmap
来接受此操作。如果有人知道这个,请帮帮我。如果有人知道什么是
MultivaluedMap
,请给我一个简单的例子?

您需要为
名称
路径表达式使用正则表达式

http://localhost:2013/RestPathParamAnnotationExample/rest/customers/Java4:kum77./@.com/USA` 
这将允许
名称
模板中的任何内容,最后一段将是
国家

试验

$curlhttp://localhost:8080/api/path/Java4:kum77./@.com/USA

Customer name-Java4:kum77.com,Country-USA

$curlhttp://localhost:8080/api/path/Java4/USA

Customer name-Java4,Country-USA


正如@peeskillet所回答的,可以使用正则表达式。这也在其本身(第3.4节URI模板)@paul samsotha中提到,
*
+
有何不同,正如大多数语言中@Shamil中提到的那样。它与正则表达式有关。
@Path("{name: .*}/{country}")
@Path("path")
public class PathParamResource {

    @GET
    @Path("{name: .*}/{country}")
    @Produces("text/html")
    public Response getResultByPassingValue(@PathParam("name") String name,
                                            @PathParam("country") String country) {

        String output = "Customer name - " + name + ", Country - " + country + "";
        return Response.status(200).entity(output).build();
    }
}