泽西岛:是否可以在@DefaultValue()批注中指定多个值 [英] Jersey : Is it possible to specify multiple values in @DefaultValue() annotation

查看:100
本文介绍了泽西岛:是否可以在@DefaultValue()批注中指定多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RESTful Web服务的Java API(JAX-RS), 并且在JAX-RS的Jersey实现中遇到@DefaultValue注释.

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

这是代码段

@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
                                        ){

我的第三个参数是List<String>,它可以有多个值

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

现在我的第三个参数的值是[age,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 . ?

推荐答案

这对您的要求不起作用.如果对象是列表类型,它将在列表中插入一个值.列表中的对象将是列表默认值的值. 检查一下为什么不尝试检查orderBy == null如果存在,则将您的默认值添加到orderBy?

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?

这篇关于泽西岛:是否可以在@DefaultValue()批注中指定多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆