Java Jersey框架中的映射方法

Java Jersey框架中的映射方法,java,web-services,jersey,Java,Web Services,Jersey,是否可以使用ID和参数将方法映射到URL路径的方法调用?例如: http://localhost/ws/updateUser/32332?name=John?psw=123 public void updateUserSting名称,字符串psw{..} 当前@PathParam注释似乎只支持path中的参数,如: http://localhost/ws/updateUser/32332/John/123尝试使用@QueryParam捕获名称和psw参数:- public void update

是否可以使用ID和参数将方法映射到URL路径的方法调用?例如: http://localhost/ws/updateUser/32332?name=John?psw=123

public void updateUserSting名称,字符串psw{..}

当前@PathParam注释似乎只支持path中的参数,如: http://localhost/ws/updateUser/32332/John/123

尝试使用@QueryParam捕获名称和psw参数:-

public void updateUser(@QueryParam Sting name, @QueryParam String psw) {
   ..
}

您可以在一个方法中组合@QueryParam和@PathParam:

@GET
@Path("/user/{userId}")
public ShortLists getShortListsOfUser(@PathParam("userId") String userId,
                                    @QueryParam("pageNumber") Integer pageNumber,
                                    @QueryParam("pageSize") Integer pageSize,
                                    @Context UriInfo uriInfo) {
   /*do something*/
}
此方法匹配/user/222?pageNumber=1和pageSize=3

使用UriBuilder运行此方法时,请注意使用queryParam:

URI uri = getBaseUriBuilder().path("/user/user111").queryParam("pageSize", 2)
              .queryParam("pageNumber", 3).build();
这不起作用:getBaseUriBuilder.path/user/user111?pageSize=2&pageNumber=3.build; 因为构建器将问号替换为%3F