我想设计一个类似于
$host/api/products?price=under+5
如何在queryparam中使用'+‘?
我可以这样做来获得那个url。
@GET
@Path("/products?price=under+{price}")
但是我该如何使用@QueryParam呢?如果我使用下面的代码,
@GET
@Path("/products")
@UnitOfWork
public Response getProducts(@NotNull @QueryParam("price") String price) {
我得到了
$host/api/products?price=5
发布于 2017-08-08 23:20:05
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
对其进行注释。
https://stackoverflow.com/questions/45576806
复制