简体   繁体   English

使用Jersey的RESTful Web服务中的路径地址

[英]Path Address in RESTful Web Service using Jersey

I have a question about Restful Web Service in java 我有一个关于java中的Restful Web Service的问题

I am completely familiar with the information in the link and how to implement a Jersey service. 我完全熟悉链接中的信息以及如何实现Jersey服务。

The path which I use is always something like this: 我使用的路径总是这样:

SERVER_ADDRESS/task/users/{username}/

SERVER_ADDRESS can be like 192.168.1.104:8080 and {username} is @PathParam SERVER_ADDRESS可以是192.168.1.104:8080 }是@PathParam

look at this address: 看看这个地址:

SERVER_ADDRESS/task/users/{username}/tasks?top=n

My question is about the end : tasks?top=n 我的问题是关于结束: tasks?top=n

I saw pretty much example with this kind of address at the end, but I don't know what is the usage of them in compare with for instance @PathParam . 我最后看到了这种地址的例子,但我不知道它们与@PathParam相比有什么@PathParam

How can we create such an idea in Jersey? 我们怎样才能在泽西岛创造这样的想法? And what is the usage of this kind of address? 这种地址的用法是什么?

To get at tasks , your must wrap it in {} in the @Path and use a @PathParam to get it. 要完成tasks ,必须将它包装在@Path中的{}中并使用@PathParam来获取它。

For top=n use a @QueryParam("top") int (if int is the type of top ). 对于top=n使用@QueryParam("top") int (如果inttop的类型)。

All this is described in the easy-to-read JAX-RS Spec , version 1.1. 所有这些都在易于阅读的JAX-RS Spec 1.1版中进行了描述。

Possible uses for @QueryParam are @QueryParam可能用途是

  • when you are passing some filters to the list you are goint to get back. 当你将一些过滤器传递给列表时,你会回来。 These filters may be optonal and does fit as path params. 这些过滤器可能是optonal并且适合作为路径参数。

  • Giving pagination limits like start and offset as a valid case. startoffset等分页限制作为有效案例。

  • Passing a list of attributes that you need. 传递您需要的属性列表。 For performance reasons you may not want the full response. 出于性能原因,您可能不希望得到完整的响应。

这将帮助您更熟悉@QueryParam - 使用@QueryParam访问查询参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM