简体   繁体   中英

Call JAX-RS Method, with optional Parameters

I have the following GET Method

@GET
@Path("alleExpats/{auswahl}/{von: .*}/{bis: .*}/{level: .*}/{location: .*}/{suche: .*}/{gam_id: .*}/{empl_rcd: .*}/{center}/{reihenfolge: .*}/{statusfarbe: .*}")
@Produces(MediaType.APPLICATION_JSON)
public List<?> alleExpats(@PathParam("auswahl") String auswahl, @PathParam("von") String von,
        @PathParam("bis") String bis, @PathParam("level") String level, @PathParam("location") String location,
        @PathParam("suche") String suche, @PathParam("gam_id") String gam_id,
        @PathParam("empl_rcd") String empl_rcd, @PathParam("center") String center
        ,@PathParam("reihenfolge") String reihenfolge,@PathParam("statusfarbe") String statusfarbe) throws ParseException 
 {

 [...]

}

As you can see, all Parameters are optional expect the "auswahl" and the "center" Parameters. So how must i write the URL from Javascript to call this Method, with these optional Parameters ?

For the moment, i call the Method like this:

URL = "api/v1/service/alleExpats/lesen/50/1//////" + filterLocationCenter + "//;

So must i write the blank Backslashes here ? Because, if i doesen't, the URL run into "no found" error.

As mentioned in the comment, use request parameters. You can use @QueryParam instead of @PathParam , and get your optional parameters from the request URI query parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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