gpt4 book ai didi

java - Jersey 端点在查询参数中使用 '+'

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:53 26 4
gpt4 key购买 nike

我想设计一个类似于的端点

$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 对其进行注释。 .

关于java - Jersey 端点在查询参数中使用 '+',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45576806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com