我正在使用用于 RESTful Web 服务的 Java API (JAX-RS) ,
并遇到@DefaultValue
JAX-RS 的 Jersey 实现中的注释。
这是代码片段
@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>
可以有多个值
例如我显式传递参数
users/query?from=100&to=200&orderBy=age&orderBy=name
现在我的第三个参数有值 [age,name]
,
但是如果我不传递任何显式参数,那么有没有办法设置多个默认值。 ?
最佳答案
这不会按照你想要的方式工作。如果对象是列表类型,它将在列表中插入一个值。列表中的对象将是列表的默认值。 Check this out为什么不尝试检查 orderBy == null
是否存在,然后将默认值添加到 orderBy
中?
关于java - Jersey : Is it possible to specify multiple values in @DefaultValue() annotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29651066/