2016-03-02 77 views
0

我有以下类为内滴料类变量条件检查规则不工作

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的会议和消防规则的数据。以下规则似乎不起作用。

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.任何人都可以建议我这种情况的解决方案来为真。

回答

1

您是否将SeniorClass类的事实插入工作记忆中?

你确定没有调用setStudentPassCount值为< = 0吗?

在规则库中是否有其他规则将锁定活动设置为true? 我强烈建议你不要使用这个属性,除非没有别的办法。

确定您的规则在语法上是正确的,以便规则库包含此规则(和其他规则)?

你打电话给fireAllRules了吗? (您是否注意到其他规则触发?)

为什么您使用矛盾的规则属性值dialect坚持其中之一。

+0

是的,我已将SeniorClass插入工作记忆中,因为我的其他规则工作正常。 studentPassCount将始终有值0或更大。 是的,还有其他规则锁定活动为真 是的,它们在语法上是正确的,因为我没有得到任何异常。 是的,我已经调用fireAllRules。 我只用两种方言来实现两者的功能。 – gomzee

+0

属于一组规则的属性锁定活动可能会禁止此规则触发。 - 您无法使用方言来达到使用这两种功能的目的;它是 - 或者。 - 无论如何,从代码和答案中不可能发现真正出错的地方。请编辑您的问题并提供创建会话和插入事实的代码。或者,检查问题是否只存在于此规则中,或显示所有规则。简而言之:所有代码重现问题,并确保陈述Drools版本。 – laune

+0

你可以在这里找到我的代码:https://github.com/gomzeegautam/sg-usersearch/tree/master/sg-usersearch和我正在使用Drools:5.3 – gomzee