通过数组作为​​参数,JAX-RS资源 [英] Pass array as parameter to JAX-RS resource

查看:443
本文介绍了通过数组作为​​参数,JAX-RS资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多参数,使用JAX-RS传递给服务器。

I have many parameters to pass to the server using JAX-RS.

有没有办法通过或AarryList的网址是什么?

Is there a way to pass or AarryList with the URL?

推荐答案

您在这里有几个选项。

You have a few options here.

您的可以的单个查询参数提供多个简单的值。例如,您的查询字符串可能看起来像:

You can supply multiple simple values for a single query parameter. For example, your query string might look like:

PUT /路径/要/我的/资源参数1 =值1&放大器;参数1 =值2和放大器;参数1 =值3

下面的请求参数参数1 有三个值,而容器会给您可以访问所有三个值作为一个数组(见的查询字符串结构)。

Here the request parameter param1 has three values, and the container will give you access to all three values as an array (See Query string structure).

如果您需要在 PUT 要求提交复杂的数据,这通常通过提供在请求体中的内容进行。当然,这种负载可以是XML(以及通过JAXB绑定)。

If you need to submit complex data in a PUT request, this is typically done by supplying that content in the request body. Of course, this payload can be xml (and bound via JAXB).

记住URI点是确定的资源( RFC 3986,3.4 ),并且如果该数组的值的是需要确定的资源数据,那么该URI是一个很好的地方。如果在另一方面,这种阵列数据的形成是在这个 PUT 要求提交的新的再presentation的一部分,那么它属于请求主体。

Remember the point of the URI is to identify a resource (RFC 3986, 3.4), and if this array of values is data that is needed to identify a resource then the URI is a good place for this. If on the other hand this array of data forms part of the new representation that is being submitted in this PUT request, then it belongs in the request body.

说了这么多,除非你真的只需要简单的值的数组,我建议选择选项2.我不能想到一个很好的理由使用URL-CN codeD XML中的URL ,但我很想听到更多有关这个数据到底是什么。

Having said that, unless you really do just need an array of simple values, I'd recommend choosing the Option 2. I can't think of a good reason to use URL-encoded XML in the URL, but I'd be interested to hear more about exactly what this data is.

这篇关于通过数组作为​​参数,JAX-RS资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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