[英]How to specify resource and id in REST URI using Jersey
Here I want to specify the id in the path of a resource to get the respective object. 在这里,我想在资源的路径中指定ID以获取相应的对象。
Example: 例:
Consider we have 10 users. 考虑我们有10个用户。 The resource URI path to get users is /users
. 获取用户的资源URI路径为/users
。
Now I want to fetch a single user by passing user id in URL like /users/1234
. 现在,我想通过在/users/1234
类的URL中传递用户ID来获取单个用户。
How can I achieve this using Jersey? 如何使用泽西岛实现这一目标?
Use a @PathParam
. 使用@PathParam
。
@GET
@Path("/users/{id}")
public Response getUser(@PathParam int id) {
// Fetch user and return Response.
}
you can use like : 你可以这样使用:
@Path("/users/{userid}")
public Response getUsr(@PathParam("userid") String userId) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.