1
情況很簡單。我創建了一個規則文件:Drools:字符串全局變量的奇怪行爲
package org.domain.rules;
dialect "mvel"
import eu.ohim.fsp.core.configuration.domain.xsd.Section;
global java.lang.String sectionName;
rule "rule 1"
salience 1000
when
Section($name : nameOfTheSection)
eval(sectionName == null)
then
System.out.println("Section: " + $name+ "("+$name.length()+")");
System.out.println("Section Name: " + sectionName + "("+sectionName.length()+")");
System.out.println("Mark Details: " + sectionName.equals(null));
end
和解聘規則之前,我添加了一個有效的coreName
節對象和全局:
public void fireInserted(Section section1) {
kstateful.insert(section1);
kstateful.setGlobal("sectionName", new String("markudetails"));
kstateful.fireAllRules();
}
結果是:
Section: markudetails(12)
Section Name: markudetails(12)
Mark Details: false
問題:怎麼可能?在時部分爲空並且在那麼部分不爲空!!!
首先:謝謝!但是,考慮在知識中插入多個部分,並且在發佈規則之前,選擇至少要在規則中測試的部分......如何執行此操作?這就是全局變量sectionName的含義。 –
我沒有回覆評論,而是改進了我的回答。 –
是的,我正在考慮這樣做。謝謝! –