我目前正在尝试向我的 REST API 添加新功能。
基本上,我想添加将查询参数添加到路径末尾的功能,并将其转换为例如所有查询选项的 Map。
我当前的代码允许我做类似的事情
localhost:8181/cxf/check/
localhost:8181/cxf/check/format
localhost:8181/cxf/check/a/b
localhost:8181/cxf/check/format/a/b
这将使用所有@pathparam 作为字符串变量来生成响应。
我现在要做的是添加:
localhost:8181/cxf/check/a/b/?x=abc&y=def&z=ghi&...
localhost:8181/cxf/check/format/a/b/?x=abc&y=def&z=ghi&...
然后我会让它生成一个 Map ,它可以与 pathparam 一起使用来构建响应
x => abc
y => def
z => ghi
... => ...
我在想这样的事情 [Below] 但是@QueryParam 似乎只处理一个键值而不是它们的映射。
@GET
@Path("/{format}/{part1}/{part2}/{query}")
Response getCheck(@PathParam("format") String format, @PathParam("part1") String part1, @PathParam("part2") String part2, @QueryParam("query") Map<K,V> query);
下面是我当前的界面代码。
@Produces(MediaType.APPLICATION_JSON)
public interface RestService {
@GET
@Path("/")
Response getCheck();
@GET
@Path("/{format}")
Response getCheck(@PathParam("format") String format);
@GET
@Path("/{part1}/{part2}")
Response getCheck(@PathParam("part1") String part1,@PathParam("part2") String part2);
@GET
@Path("/{format}/{part1}/{part2}")
Response getCheck(@PathParam("format") String format, @PathParam("part1") String part1, @PathParam("part2") String part2);
}