[英]Jersey endpoint using '+' in queryparam
I want to design an endpoint similar to 我想设计一个类似于
$host/api/products?price=under+5
How can I use '+' in queryparam? 如何在queryparam中使用“ +”?
I could do like this to get that url 我可以这样获取网址
@GET
@Path("/products?price=under+{price}")
But How can I do using @QueryParam? 但是,如何使用@QueryParam? If I use the following,
如果我使用以下内容,
@GET
@Path("/products")
@UnitOfWork
public Response getProducts(@NotNull @QueryParam("price") String price) {
I get 我懂了
$host/api/products?price=5
The value of the price
query parameter must be URL encoded . price
查询参数的值必须经过URL编码 。 When URL encoded, the +
character becomes %2B
. 对URL进行编码后,
+
字符变为%2B
。 So you'll have under%2B5
. 因此,您将拥有
under%2B5
。
With it, the following should work fine: 有了它,以下应该可以正常工作:
@GET
@Path("/products")
public Response getProducts(@NotNull @QueryParam("price") String price) {
// the value of price will be: under+5
...
}
If you don't want the JAX-RS runtime to decode the price
parameter, annotate it with @Encoded
. 如果您不希望JAX-RS运行时对
price
参数进行解码,请使用@Encoded
对其进行@Encoded
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.