我正在上以下类(class)
public class SeniorClass {
List<Students> stud;
String highScorerMath;
String highScorerChemistry;
String highScorerPhysics;
String highScorerEnglish;
int studentPassCount=2;
public String getHighScorerMath() {
return highScorerMath;
}
public void setHighScorerMath(String highScorerMath) {
this.highScorerMath = highScorerMath;
}
public String getHighScorerChemistry() {
return highScorerChemistry;
}
public void setHighScorerChemistry(String highScorerChemistry) {
this.highScorerChemistry = highScorerChemistry;
}
public String getHighScorerPhysics() {
return highScorerPhysics;
}
public void setHighScorerPhysics(String highScorerPhysics) {
this.highScorerPhysics = highScorerPhysics;
}
public String getHighScorerEnglish() {
return highScorerEnglish;
}
public void setHighScorerEnglish(String highScorerEnglish) {
this.highScorerEnglish = highScorerEnglish;
}
public int getStudentPassCount() {
return studentPassCount;
}
public void setStudentPassCount(int studentPassCount) {
this.studentPassCount = studentPassCount;
}
public List<Students> getStud() {
return stud;
}
public void setStud(List<Students> stud) {
this.stud = stud;
}
}
当我将与此类相关的数据插入 Drools session 和触发规则时。遵循规则似乎不起作用。
rule "Students passed count"
lock-on-active true
dialect "mvel"
dialect "java"
salience 0
when
$sc : SeniorClass(studentPassCount > 0);
then
System.out.println(" Rule 6: Total no. of Students passed are: " + $sc.getStudentPassCount());
end
我不确定为什么我的“studentPassCount > 0”条件检查不成立,即使在类里面我已将此变量值设置为 2。任何人都可以建议我针对这种情况的解决方案。
最佳答案
您是否将 SeniorClass 类的事实插入到工作内存中?
您确定 setStudentPassCount 调用时的值不是 <= 0 吗?
您的规则库中是否还有其他将 lock-on-active 设置为 true 的规则? 我强烈建议您不要使用此属性,除非没有其他办法。
您确定您的规则在语法上正确,以便规则库包含此规则(和其他规则)吗?
你调用了 fireAllRules 吗? (您是否观察到其他规则被触发?)
为什么对 dialect
使用相互矛盾的规则属性值? 坚持其中之一。
关于java - drools 规则内类变量的条件检查不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35745440/