java自定义Jersey参数解组
我收到一个字符串行作为查询参数,如
parameter=123,456,789
我想直接在我的控制器中获得List<Integer>
。大概是这样的:
@GET
@Path(REST_PATH)
@Produces(MediaType.APPLICATION_JSON)
public Response getSomeStuff(@MagicalThing("parameter") List<Integer> requiredList)
除了自定义提供程序和其他类型外,可以执行哪些操作:
https://stackoverflow.com/a/6124014
更新:自定义注释解决了难题http://avianey.blogspot.de/2011/12/exception-mapping-jersey.html
# 1 楼答案
没有内置的机制来实现这一点。您需要自己在方法或提供程序中拆分该字符串,或者在您自己的对象中拆分该字符串,该对象具有带字符串参数的构造函数,例如:
其中MyList可能是:
然后用你的方法得到我的名单