我尝试使用RESTEasy客户端调用服务发送列表作为查询参数:
服务:
final MultivaluedMap<String, Object> queryParams = new MultivaluedMapImpl<>();
queryParams.add("name", "name1");
queryParams.add("name", "name2");
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client.target(url).queryParams(queryParams);
final Builder builder = target.request();
builder.accept(MediaType.APPLICATION_JSON);
final Response response = builder.post(Entity.form(form));
客户端:
/names
当我调用names.get(0) == [name1, name2]
端点时,将有1个元素和.click()
答案 0 :(得分:1)
问题解决了。我最近发布的代码效果很好。
错误的代码是:
final List<String, String> list = new ArrayList<>();
list.add("name1");
list.add("name2");
final MultivaluedMap<String, Object> queryParams = new MultivaluedMapImpl<>();
queryParams.addAll("name", list);
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client.target(url).queryParams(queryParams);;
final Builder builder = target.request();
builder.accept(MediaType.APPLICATION_JSON)
final Response response = builder.post(Entity.form(form));
如果我查看类MultivaluedMapImpl的代码,如果我使用&#34;添加&#34;我就不会发现差异。或者&#34; addAll&#34;方法!!