Jersey : Is it possible to specify multiple values

2019-02-27 10:09发布

I am playing around with Java API for RESTful Web Services (JAX-RS) , and encountered @DefaultValue annotation in Jersey implementation of JAX-RS.

Here is the code snippet

@GET
@Path("/query")
public Response getUserWithQueryParams(
    @DefaultValue("defaultId") @QueryParam("from")String from,
    @DefaultValue("defaultName") @QueryParam("to") String to,
    @DefaultValue("mobileNo")@QueryParam("orderBy") List<String> orderBy
                                        ){

My third argument is of List<String> which can have multiple values

for example I explicitly pass the parameters

users/query?from=100&to=200&orderBy=age&orderBy=name

Now my third argument have values [age,name] ,

but if i don't pass any explicitly parameter then Is there any way to set multiple default values . ?

1条回答
混吃等死
2楼-- · 2019-02-27 10:56

This won't work how you want it to. If the object is type List it will have a single value inserted in the list. The object in the list will be the value of your default value for the list. Check this out Why not try checking if orderBy == null if it does then add your default values to orderBy?

查看更多
登录 后发表回答