[英]How to merge multiple path parameters into one object
I have a route that looks like this: 我有一条看起来像这样的路线:
/foobar/123/2
And I would like to use all three parameters to get a single object so that I can use something like this: 而且我想使用所有三个参数来获取单个对象,以便可以使用类似以下的内容:
@Path("/{type}/{id}/{version}")
public Response getEntity(Entity entity);
Instead of: 代替:
@Path("/{type}/{id}/{version}")
public Response getEntity(@PathParam("type") Type type, @PathParam("id") Long entityId, @PathParam("version") Long version);
ParamConverter
looks promising, however it can only handle a single String
not three. ParamConverter
看起来很有希望,但是它只能处理一个String
而不是三个。 Anything else I could try? 还有什么我可以尝试的吗?
I believe you are out of luck. 我相信你不走运。
From JSR-000339 "Java[TM] API for RESTful Web Services 2.0 Final Release for evaluation " 摘自JSR-000339 “用于RESTful Web服务2.0的Java™API最终发布以进行评估”
the following types are supported
支持以下类型
- Types for which a ParamConverter is available via a registered ParamConverterProvider .
通过已注册的ParamConverterProvider可以使用ParamConverter的类型 。 See Javadoc for these classes for more information.
有关更多信息,请参见Javadoc。
- Primitive types
原始类型
- Types that have a constructor that accepts a single String argument.
具有接受单个String参数的构造函数的类型。
- Types that have a static method named valueOf or fromString with a single String argument that return an instance of the type.
具有名为valueOf或fromString的静态方法且带有单个String参数(返回该类型的实例)的类型。 If both methods are present then valueOf MUST be used unless the type is an enum in which case fromString MUST be used.
如果两种方法都存在,那么除非该类型是一个枚举,否则必须使用valueOf,在这种情况下必须使用fromString。
- List, Set, or SortedSet, where T satisfies 3 or 4 above
列表,集合或排序集合,其中T满足以上3或4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.