gpt4 book ai didi

java - 我可以在查询参数中使用 Map<> 吗?

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:33 25 4
gpt4 key购买 nike

我可以在查询参数中使用 Map 吗?我有许多 REST 资源,我想在一处更改查询参数列表,我有这样的来源:

@GET
@Path("...")
@Produces({MediaType.APPLICATION_JSON})
public String getPath(
@PathParam("...") String path,
@QueryParam("headers") Map<String, String> headers // error!

如何使用动态查询参数列表?因为标题将来会改变

最佳答案

摘自 Oracle 关于 extracting request parameters 的文档,您应该能够使用 @Context 注释将 header 传递到您的方法中:

@GET
@Path("...")
@Produces({MediaType.APPLICATION_JSON})
public String getPath(
@PathParam("...") String path,
@Context HttpHeaders headers) {
...

然后通过HttpHeaders上的方法访问 header 和cookie实例。我还没有尝试过,但看起来应该可行。

关于java - 我可以在查询参数中使用 Map<> 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505868/

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