0

我正在使用 Optaplanner 6.2Final 版本,除了匹配运算符外,一切正常。为了解释更多,这是我的规则。

rule "TEST REG EXP OPERATOR"
when
    $cheese:Cheese($cheese.type matches "(Buffulo)?\\S*Mozarella")
then
    scoreHolder.addSoftConstraintMatch(kcontext, 1);
end

以下是抛出的异常:

Exception in thread "main" [Error: unable to resolve method: com.app.test.domain.Cheese.$cheese() [arglength=0]]
[Near : {... $cheese.type ~= "(Buffulo)?\\S*Mozarella" ....}]

注意:如果我删除了 $cheese. 在type前面声明,规则没有问题。这工作正常:

$cheese:Cheese($cheese.type == "Buffulo")

任何建议,将不胜感激。

更新: 事实证明,在我检查完所有版本后,以下仅在 drools 核心版本 6.2.0.Final 和 6.3.0.Final 上引发异常。它适用于其余版本。

$cheese:Cheese($cheese.type matches "(Buffulo)?\\S*Mozarella")
4

1 回答 1

0

如果你想让这个工作:

  $cheese1:Cheese(type matches "(Buffulo)?\\SMozare‌​lla")
  $cheese2:Cheese($che‌​ese1.name matches "A.*", id>$cheese1.id)

你必须使用方法调用:

  $cheese1:Cheese(type matches "(Buffulo)?\\SMozare‌​lla")
  $cheese2:Cheese($che‌​ese1.getName() matches "A.*", id>$cheese1.getId())

这假设您一直遵循 JavaBeans 约定(您应该这样做)。但更好的是使用

  $cheese1:Cheese(type matches "(Buffulo)?\\SMozare‌​lla",
                  name matches "A.*", $id1: id )
  $cheese2:Cheese( id > $id1 )
于 2016-08-16T08:42:18.523 回答