如何在 Struts 2 JSON 插件中指定地图属性
我使用 Struts 2 和 json 插件,struts.xml 文件中的属性映射通常令人沮丧,但我能够弄清楚它们。
我遇到过一种情况,我无法设置 includeProperties 来给我预期的结果。
我经常使用配置表达式,
^itemList\[\d+\]\.id,
^itemList\[\d+\]\.name
....
这效果很好。
在这种情况下,我想从地图而不是列表(或作为列表成员的子级的地图)返回数据
如果使用*,则整个地图都会正确打印出来,但我不希望来自列表的所有数据地图元素。
^itemList\[\d+\]\map\.*
返回整个地图
我尝试了几种不同的格式,但没有一个产生结果。
^itemList\[\d+\]\map\[\d+\]\.id
^itemList\[\d+\]\map\[\d+\]\.name
地图属性中没有返回任何内容
有人有幸使用语法来限制地图的内容吗?
谢谢 -斯科特
I'm using Struts 2 along with the json plugin, the properties mappings in the struts.xml file are typically frustrating but I am able to figure them out.
I have come across a case where I cannot set the includeProperties to give me the result I expect.
Frequently I use a configuration expression
^itemList\[\d+\]\.id,
^itemList\[\d+\]\.name
....
This works well.
In this case I would like to return data from a Map not a list (or a map that's a child of a list member)
If a * is used the whole map is printed out correctly, but I do not want all the data from the map elements.
^itemList\[\d+\]\map\.*
The whole map is returnd
I have tried several different formats and none of them have produced results.
^itemList\[\d+\]\map\[\d+\]\.id
^itemList\[\d+\]\map\[\d+\]\.name
Nothing is returned in the map property
Anyone had any luck with a syntax to restrict the contents of a map?
Thanks
-Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用“d”将其映射为整数。
试试这个
^itemList\..*$
You cannot use 'd' it map as integer.
Try this
^itemList\..*$
1)你的正则表达式很可疑。请注意,在表达式“^itemList[\d+]\map[\d+].id”中,+d 指的是多一位数字,因此地图必须将数字作为键。如果这不是您想要的,那么“.+”可能更合适(一个或多个任何字符)。
2)将Map转换为LinkedHashMap,然后将其视为列表。 (没有测试过,可能行不通)
1) Your regular expression is suspicious. Note that in the expression "^itemList[\d+]\map[\d+].id", +d refers to one more more digits, so the map would have to have digit(s) as it's key. If this is not what you want, then '.+' is probably more appropriate (one or more of any character).
2) Convert the Map to a LinkedHashMap and then treat it as a list. (Have not tested this, it might not work)