在决策表中插入关键字



我是Drools的新手,并且通过一个包含insert($param)insert(new Object($param))的现有用例,我无法找到这个关键字的功能及其范围,以及如何在进一步的条件下利用它。

任何对此的回应或文档都会有所帮助。我在任何文档中都找不到这个

我强烈建议您阅读这里的官方文档:https://docs.drools.org/8.32.0.Final/drools-docs/docs-website/drools/rule-engine/index.html

Drools中规则的条件适用于"事实";存在于KieSession中。这些"Facts"都是Java对象。如果你想让一个对象成为"事实"然后你需要插入它变成了KieSession。否则,Drools将不知道它的存在,也不会对它应用任何规则。

因此,例如,如果您在KieSession中有以下规则:

rule "Adult Person"
Person(age >= 18)
then
//do something
end

Person模式引用了一个名为"person"的Java类。在Java中,如果你想让Person实例对KieSession可用,你需要做这样的事情:

Person person = new Person();
person.setAge(33); // up to this point, Drools is not aware of this object
kieSession.insert(person); //here we are telling Drools that the `person` object is a Fact and that the rules have to be evaluated for it.

在您的情况下,insert函数被调用作为您的规则的一部分,而不是直接从Java,但思想是相同的。

最新更新