Drools 在 where 子句中获取 List 的第一个元素
Drools get first element of List in where clause
是否可以从 Drools 中的 when 子句中获取列表的第一个元素?
如果我不知道列表中的对象字段值并且我只想检索第一个元素,我该怎么做?
rule "TestRule1"
dialect "java"
when
$c : Collection()
$listCustObjs : ArrayList() from collect (CustomObject() from $c)
$first : $listCustObjs.get(0) //<- something like this
$otherObj : $first.other // <- take other element from first object from the list
then
...
end;
您需要将 $listCustObjs 对象转换为 List,然后您才能使用列表方法。使用“#”运算符在 drools 中进行转换。检查 here.
也可以直接使用$first : $listCustObjs.get(0)
这样的语句。当所有计算或条件检查都在事实即对象上完成时,流口水。因此,在您的情况下,当您尝试将值放入对象中时,您只能从 $listCustObjs 列表中获取值。
是否可以从 Drools 中的 when 子句中获取列表的第一个元素? 如果我不知道列表中的对象字段值并且我只想检索第一个元素,我该怎么做?
rule "TestRule1"
dialect "java"
when
$c : Collection()
$listCustObjs : ArrayList() from collect (CustomObject() from $c)
$first : $listCustObjs.get(0) //<- something like this
$otherObj : $first.other // <- take other element from first object from the list
then
...
end;
您需要将 $listCustObjs 对象转换为 List,然后您才能使用列表方法。使用“#”运算符在 drools 中进行转换。检查 here.
也可以直接使用$first : $listCustObjs.get(0)
这样的语句。当所有计算或条件检查都在事实即对象上完成时,流口水。因此,在您的情况下,当您尝试将值放入对象中时,您只能从 $listCustObjs 列表中获取值。