[英]Rule Compilation error : Can only iterate over an array or an instance of java.lang.Iterable
I am new to mongoDb and drools. 我是mongoDb和流口水的新手。 I am writing a rule in drools, which is iterating a java list. 我在流口水中写了一条规则,该规则正在迭代Java列表。 But when running tomcat it is giving Rule Compilation error. 但是当运行tomcat时,它会给出规则编译错误。
Getting List from dao :- 从dao获取列表:-
List<XYZ> list = new ArrayList<XYZ>();
Query q = query(where("id").is(userId));
list = getMongoOperation().find(q, XYZ.class, "XYZ");
Using list in drools engine Rule :- 在drools引擎中使用列表规则:-
for(XYZ xyzObj : list)
{
}
Model Class :- 型号类别:-
@Document(collection="XYZ")
public class XYZ
{
}
I am getting exception when running tomcat. 运行tomcat时出现异常。 "Rule Compilation error : Can only iterate over an array or an instance of java.lang.Iterable" “规则编译错误:只能迭代数组或java.lang.Iterable的实例”
Rule File :- 规则文件:-
import java.util.List; 导入java.util.List; import java.util.Iterator; 导入java.util.Iterator; global com.demo.XYZ list 全局com.demo.XYZ列表
rule '1_Demo_Rule' 规则“ 1_Demo_Rule”
when prop : RULEDEMO( attribute == "demo") then 当prop时:RULEDEMO(attribute ==“ demo”)然后
for(XYZ xyzObj : list) { }
end 结束
You will not be able to use the short syntax of the for-statement at all, due to restrictions in the DRL parser. 由于DRL解析器中的限制,您将根本无法使用for语句的简短语法。
Given that 鉴于
global List<com.demo.XYZ> list;
use the not-so-nice 使用不太好
for( int i = 0; i < list.size(); i++ ){
XYZ xyzObj = list.get(i);
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.