drools drl
Let us demonstrate how to call a static function from a java file within your DRL
file. Creating a class Utility.java
in the same package com.sample
让我们演示如何从DRL
文件中的Java文件中调用静态函数。 在同一包com.sample
创建一个类Utility.java
public class Utility {
public static void writeHello(String name) {
System.out.println("HELLO" + name + "!!!!!!");
}
}
We then add the import statement in our drl file to call the writeHello
method from our drl file. Again we have added the syntax in the same drl file used
然后,我们在drl文件中添加import语句,以从我们的drl文件中调用writeHello
方法。 同样,我们在使用的同一drl文件中添加了语法
此方案的用例: (Use case for this scenario:)
Following is a step by step explantion for the usecase:
以下是用例的逐步移植:
There are lot of times where you need to do calculation with respect to the parameters of your Object which you are using in your DRL's or for that matter you need to check whether the particular variable is a part of some static data or a static configuration and based on that decision you want to execute your rule, so at such places it's advisable to call a external function either in your
DRL
file or in yourUtility
class so that processing can be done in those functions and the rules can act on the output of your function.很多时候,您需要针对在DRL中使用的对象参数进行计算,或者为此,您需要检查特定变量是某些静态数据还是静态配置的一部分,并且根据您要执行规则的决定,因此建议在此类位置调用
DRL
文件或Utility
类中的外部函数 ,以便可以在这些函数中进行处理,并且这些规则可以作用于您的功能。Primarily Drools is meant for the business layer i.e to evaluate what to do next if a particular condition is met and hence the processing part in case if needed for specific rules can be done in function and hence the provision given.
主要是Drools用于业务层,即在满足特定条件的情况下评估下一步要做什么,因此,如果可以在功能上完成特定规则的需要,则处理部分,因此提供了相应的规定。
Another example is that Java is a Object oriented language but it still lets you write static/helper functions to do some calculations and use static method without initiating any object. It is against the object oriented programming concept but still we can directly call a method without creating a object, so similarly Drools also provides that feature.
另一个例子是Java是一种面向对象的语言,但是它仍然允许您编写静态/辅助函数来进行一些计算并使用静态方法而无需初始化任何对象。 这与面向对象的编程概念背道而驰,但是我们仍然可以直接调用方法而无需创建对象,因此类似地,Drools也提供了该功能。
翻译自: https://www.studytonight.com/drools/external-function-drl-file
drools drl