drools - 异常“无法解析 ObjectType 'getAmount'”
问题描述
在 Drools 中,我创建了一个包含以下内容的 drl 文件:
import com.myorg.model.UserAccount;
import function com.myorg.utils.UserAccountHelper.getAmount;
rule "Classification userC"
when
$user : UserAccount(_age < 50);
$amount: getAmount($user, "single");
then
$user.set_userClassification("userC");
end
在 Java 中我有一个静态方法 UserAccountHelper.getAmount
public static double getAmount(UserAccount account, String status)
{
double amount = 0d;
switch(status)
{
case "single":
if (account.canBeFullyRefunded)
amount = 1000;
else
amount = 100;
default:
amount = 0d;
}
return amount;
}
验证 drl 文件时出现异常“无法解析 ObjectType 'getAmount'”。有人可以帮忙吗?我正在使用 Drools 7.37。
解决方案
这不是在 DRL 中调用类的静态方法的方式。我建议您查看文档以更好地理解语法。
如果要在 Pattern 中调用静态(或实例)方法,可以这样做:
rule "Classification userC"
when
$user : UserAccount(
_age < 50,
$amount: getAmount(this, "single")
)
then
$user.set_userClassification("userC");
end
推荐阅读
- python - How to subscribe a common characteristic for all the slaves connected with BLED112 in Windows 10?
- python - 非对称双 sigmoid 函数拟合 NDVI 时间序列
- powershell - Powershell 从过去 5 分钟获取行
- javascript - Oracle JET 如何在 JS 文件中包含数据?
- flutter - 从 RawDatagramSocket (Flutter) 返回数据报
- flutter - 如何在另一个选项卡的正常滚动中使用 sliver appbar 不重置列表视图的列表位置
- kubernetes - 是否有任何参数可以增加 Istio 虚拟服务清单中的默认 http 响应大小?
- python - 我需要使用 Python+Selenium 打开一个新选项卡并将 URL 粘贴到浏览器的 Url 行。由于某种原因不适用于 Keys
- flutter - Dart 中的全局变量:单例与静态
- windows - 如何通过 bash 在文件资源管理器中打开 Windows 启动文件夹?