Drools Rule-针对布尔字段的编写规则,名称以“ is”开头 [英] Drools Rule - writing rule against boolean field, name starting with "is"

查看:151
本文介绍了Drools Rule-针对布尔字段的编写规则,名称以“ is”开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在drools规则中,想要测试布尔字段isValid的值(注意:字段名称以 is开头)。出现以下错误:

In a drools rule, wanted to test for the value of a boolean field isValid (note: field name starts with "is"). Getting the below error:


无法为规则'[ClassObjectType class = domain.SpecialObject]'的'isValid'创建字段提取器测试布尔值的东西':[规则名称='测试布尔值的东西']
线程主中的异常java.lang.IllegalArgumentException:无法解析drl文件。

Unable to create Field Extractor for 'isValid' of '[ClassObjectType class=domain.SpecialObject]' in rule 'Test boolean stuff' : [Rule name='Test boolean stuff'] Exception in thread "main" java.lang.IllegalArgumentException: Could not parse drl files.

但是,规则中的另一个布尔字段 solid也可以正常工作。

However, another boolean field "solid" within the rule works fine.


环境:Drools版本-5.1.1,dialect = mvel

Environment: Drools version - 5.1.1, dialect=mvel



<Drl file>
import deshaw.compliance.regsys.dep.domain.SpecialObject;
dialect "mvel"
rule "Test boolean stuff"
no-loop
  when
    $obj: SpecialObject(isValid == true)  // -->Problematic guy
    //$obj: SpecialObject(solid == true)  // -->This works fine
then
   System.out.println("[SplObject]:Class=" + $obj.class + ";;;obj=" + $obj);
end

<domain object>
public class SpecialObject {

private boolean isValid;
private boolean solid;

public boolean isValid() {
    return isValid;
}

public void setValid(boolean isValid) {
    this.isValid = isValid;
}

public boolean isSolid() {
    return solid;
}

public void setSolid(boolean solid) {
    this.solid = solid;
}

}

注意:该类属于一个第三方lib,因此我无法更改 isValid字段的名称

Note: The class belongs to a third party lib and hence I cannot change the name of "isValid" field

推荐答案

尝试

when
  $obj : SpecialObject( valid == true )
then
   ...

由于属性的访问者为 isValid ,因此应将其称为<$来自mvel的c $ c>有效。另一种选择是使用带有方括号的完整方法名称。

Since the accessor of the attribute is isValid you should refer to it as valid from mvel. Another alternative is using full method name with brackets.

字段名称本身无关紧要,但是如果作者坚持使用命名标准会更好。

Name of the field itself is irrelevant, although it would be better if the author had adhered to naming standards.

这篇关于Drools Rule-针对布尔字段的编写规则,名称以“ is”开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆