Jersey Matching Methods

Is it possible to map methods to call methods with a URL with both an identifier and parameters? For example: Http:? // local / WS / updateUser / 32332 = name John PSW = 123

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

It seems that the current @PathParam annotation only supports parameters in the path, for example: http: // local / WS / updateUser / 32332 / John / 123

+4
source share
2 answers

Try using @QueryParam to capture the name and psw : -

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

You can combine @QueryParam and @PathParam in one way:

 @GET @Path("/user/{userId}") public ShortLists getShortListsOfUser(@PathParam("userId") String userId, @QueryParam("pageNumber") Integer pageNumber, @QueryParam("pageSize") Integer pageSize, @Context UriInfo uriInfo) { /*do something*/ } 

Does this method correspond to http: // localhost / api / user / 222? pageNumber = 1 & pageSize = 3


When using UriBuilder to run this method, be sure to use queryParam:

 URI uri = getBaseUriBuilder().path("/user/user111").queryParam("pageSize", 2) .queryParam("pageNumber", 3).build(); 

This does not work: getBaseUriBuilder (). path ("/ user / user111? pageSize = 2 & pageNumber = 3"). build (); (because the question mark is replaced with% 3F by the builder)

0
source

Source: https://habr.com/ru/post/1345237/


All Articles