在 MVEL 中处理集合
Dealing with collections in MVEL
我有以下字段:
List<Map<String, Long>> vehicles;
其中每张地图包含 2 对:
"id" -> N
"order" -> M
如何通过id
找到地图并在MVEL中提取对应的order
?
在 Java 中看起来像:
vehicles.stream().find(m -> m.get("id") == N).findAny().map(m -> m.get("order")).orElse(0);
事实证明,可以通过以下方式迭代地图列表、过滤它们并提取值:
order: Number() from accumulate(
Map(this["id"] == N, $ord: this["order"]) from vehicles, max($ord)
)
我有以下字段:
List<Map<String, Long>> vehicles;
其中每张地图包含 2 对:
"id" -> N
"order" -> M
如何通过id
找到地图并在MVEL中提取对应的order
?
在 Java 中看起来像:
vehicles.stream().find(m -> m.get("id") == N).findAny().map(m -> m.get("order")).orElse(0);
事实证明,可以通过以下方式迭代地图列表、过滤它们并提取值:
order: Number() from accumulate(
Map(this["id"] == N, $ord: this["order"]) from vehicles, max($ord)
)