泽西终点使用' +'在queryparam中

时间:2017-08-08 19:41:16

标签: java jersey jersey-2.0 dropwizard

我想设计一个类似于

的端点
$host/api/products?price=under+5

我如何使用' +'在queryparam?

我可以这样做以获取该网址

@GET
@Path("/products?price=under+{price}")

但是如何使用@QueryParam?如果我使用以下内容,

@GET
@Path("/products")
@UnitOfWork
public Response getProducts(@NotNull @QueryParam("price") String price) {

我得到了

$host/api/products?price=5

1 个答案:

答案 0 :(得分:0)

price查询参数的值必须为网址编码。对URL进行编码时,+字符变为%2B。所以你有under%2B5

有了它,以下应该可以正常工作:

@GET
@Path("/products")
public Response getProducts(@NotNull @QueryParam("price") String price) {
    // the value of price will be: under+5
    ...
}

如果您不希望JAX-RS运行时解码price参数,请使用@Encoded对其进行注释。