简体   繁体   中英

ignore optional @Query parameters

Is there a possibility to ignore some of the optional @Query parameters dynamic if the corresponding value is not declared?

@Path("/users")
public class Services {

@GET
@Path("/get")
public Response getUsers(
    @QueryParam("from") int from,
    @QueryParam("to") int to,
    @QueryParam("age") int age,
    @QueryParam("name") String name
    @QueryParam("username") String username) 

In JAX-RS parameters are not mandatory, if you don't send value to parameters the default value will be null , you can also use @DefaultValue annotation to provide default value.

Use can also use spring frame work @RequestParam and you can specify required=false so which is optional here

You could use @DefaultValue so if the param is not filled you get the default value

https://www.mkyong.com/webservices/jax-rs/jax-rs-queryparam-example/

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