如何在Drools中调用Java函数? [英] How to call a Java function in drools?

查看:877
本文介绍了如何在Drools中调用Java函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Utils类调用Java函数,该类调用用于检索自定义对象的JPA Repository方法.

I want to call a Java function from a Utils class which calls a JPA Repository method for retrieving a custom object.

我想从Drools决策表中调用此函数. 现在,这个简单的函数提供了Null Pointer Exception(空指针异常),而我已经在此上浪费了几个小时.

I want to call this function from a Drools decision table. Now, this simple function is giving Null Pointer Exception and I have already lost several hours on this.

我在决策表的导入"部分下声明了一个函数"字段,并在那里声明了一个简单的函数,该函数使用存储库方法调用此特定的Java函数.

I have a Functions field declared under "Import" section of the decision table, and there I have declared a simple function which calls this particular Java function with the repository method.

您能为我提供解决方案吗?

Can you provide me with a solution?

推荐答案

以下是从流口水中调用Java方法的示例. setLocalTax()方法可从ItemCity类获得.使用"$ item"对象,我们可以调用.

Here is an example of calling java method from drools. setLocalTax() method is available from ItemCity class. Using the '$item' object we can invoke.

package droolsexample

// list any import classes here.
import com.sample.ItemCity;
import java.math.BigDecimal;

// declare any global variables here
dialect "java"
rule "Pune Medicine Item"

   when
      $item : ItemCity (purchaseCity == ItemCity.City.PUNE,
                       typeofItem == ItemCity.Type.MEDICINES)

   then
      BigDecimal tax = new BigDecimal(0.0);
      $item.setLocalTax(tax.multiply($item.getSellPrice()));
end

这篇关于如何在Drools中调用Java函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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