我是Web服务和新手;在创建接受GET请求的Web服务时,我找到了两种可以读取URL参数的方法:
getPathParameters()& UriInfo的getQueryParameters()。当我尝试执行两个时,我得到了相同的输出。这是我试图运行的代码:
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
public String processGETReq(@Context UriInfo pUriInfo) {
MultivaluedMap<String, String> queryParams = pUriInfo.getQueryParameters();
MultivaluedMap<String, String> pathParams = pUriInfo.getPathParameters();
Set<Entry<String, List<String>>> lQueryParamsSet = queryParams.entrySet();
Set<Entry<String, List<String>>> lPathParamsSet = pathParams.entrySet();
for (Entry<String, List<String>> lQueryEntrySet : lQueryParamsSet) {
System.out.println(lQueryEntrySet.getValue());
System.out.println(lQueryEntrySet.getKey());
}
for (Entry<String, List<String>> lPathEntrySet : lPathParamsSet) {
System.out.println(lPathEntrySet.getValue());
System.out.println(lPathEntrySet.getKey());
}
}
两者的输出相同。所以,我很想知道它们之间有什么区别。试图从文档中获取它(http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/UriInfo.html),但没有正确区分。
提前感谢您的回答!!
答案 0 :(得分:2)
/clients/123/sales?sort=asc
clientId=123
是路径参数,sort=asc
是查询参数。