在查询参数中使用'+'的泽西端点



我想设计一个类似于

$host/api/products?price=under+5

如何在查询参数中使用"+"?

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

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

但是我该如何使用@QueryParam呢?如果我使用以下方法,

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

我得到

$host/api/products?price=5

price查询参数的值必须进行 URL 编码。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对其进行批注。

最新更新