drools drl_Drools:如何从.drl文件调用外部函数

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 your Utility 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值