将字符串列表映射到操作中定义的 ArrayList class - Struts2

Map a list of strings to an ArrayList defined in the action class - Struts2

www.abcd.com/user/getuserstats.htm?userId=123123

在此 api 中,userId 被设置为映射到此操作的 Action class 中名为 userId 的字段。

现在,为此

www.abcd.com/user/getuserstats.htm?listOfUsers=123123,456456,789789,42568,58963

我需要知道如何将这个 userId 列表映射到相应 Action class 中定义的 ArrayList 中,以便将其映射为ArrayList 不是 String.

注意:我不想获取一串 userId 并将其转换为 ArrayList later.I 希望 userIds 列表自动映射到列表中或 ArrayList。我相信一定有办法实现这一目标。

基本上,我发现可以这样实现:

www.abcd.com/user/getuserstats.htm?userId=123123&userId=4578&userId=567&userid=987

这些参数将进入已在操作中声明的数组列表 class。

这些值可以 CSV 格式提交。 Struts2 有一个内置类型转换器,它能够填充一个 属性 集合,例如列表。

使用多个同名参数的解决方法是可行的,但无需使用 Struts2 类型转换。最后一个是框架提供的强大功能之一,不使用它是不明智的。

此功能的更详细说明是here

The values should be in the CSV format like in this answer.

That will also give you an idea about type of property which you should bind to the hidden field. For example you can use List or Integer[] for the property that set the values 25, 27, 28.

Struts2 has a built-in converter that converts such values to the list or array automatically.