Play 2.0 Java:从请求绑定数组 [英] Play 2.0 Java: Bind an array from request

查看:66
本文介绍了Play 2.0 Java:从请求绑定数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我...卡住了.

我有国外要求的参数:

param[62537]=abc;
param[20356]=cde;
param[92837]=fgh;

我正在寻找任何方式来绑定它们,即.用DynamicForm.

And I'm looking for any way for binding them ie. with DynamicForm.

我可以通过以下方式获得参数

I can get param with:

DynamicForm dynamicForm = form().bindFromRequest();
String firstParam = dynamicForm.field("param[62537]").value();

但是我当然不知道,因为它们是在独立应用程序创建的client-side表单中选择的.

But of course I dont know the indexes as they are selected within the client-side form created by the independent app.

当我尝试使用时:

String[] firstParam = dynamicForm.field("param").value(); // it's NULL
String[] firstParam = dynamicForm.get("param"); // it's NULL

甚至

String[] params = request().body().asFormUrlEncoded().get("param");
     // it's still NULL

我错过了一些非常基本的东西吗,或者Play不能做到这一点?

Did I miss something really basic, or Play just can't do that?

推荐答案

不是最漂亮的方法,但是您是否尝试获取asFormUrlEncoded返回的Map的键:

Not the prettiest way, but did you try to get the keys of the Map returned by asFormUrlEncoded:

Set<String> keys = request().body().asFormUrlEncoded().keySet();
for (String key : keys) {
     // check if key begin with "param["
}

这篇关于Play 2.0 Java:从请求绑定数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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