当前位置:网站首页>Drools(5):Drools高级语法
Drools(5):Drools高级语法
2022-07-27 05:45:00 【不死鸟.亚历山大.狼崽子】
高级语法
| 关键字 | 描述 |
package | 包名,只限于逻辑上的管理,同⼀个包名下的查询或者函数可以直接调⽤ |
import | ⽤于导⼊类或者静态⽅法 |
global | 全局变量 |
function | ⾃定义函数 |
query | 查询 |
rule end | 规则体 |
global全局变量
全局变量,⼀般⽤作执⾏规则后的结果数据返回或对具体某个服务调⽤等,如⼀个电子邮件服务的实例,在调⽤规则引擎的集成代码中,获取emailService对象,然后将其设置在⼯作内存中。
语法结构为:global 对象类型 对象名称
示例:
package rules
import java.util.List;
global java.util.List myGlobalList;
//如果在规则⽂件中使⽤了全局变量,那么必须在规 则引擎中设置全局变量值
rule "global_rule1"
when
eval( true )
then
myGlobalList.add( "Hello World" );
// System.out.println("global_rule1 is execution...");
end
rule "global_rule2"
when
eval( true )
then
System.out.println("myGlobalList集合的元素个数:"+myGlobalList.size());
System.out.println("global_rule2 is execution...");
end测试:
@Test
public void test13() throws InterruptedException {
KieServices kieServices = KieServices.Factory.get();
KieContainer kieClasspathContainer = kieServices.getKieClasspathContainer();
KieSession kieSession = kieClasspathContainer.newKieSession();
List list = new ArrayList();
设置全局变量,名称和类型必须和规则⽂件中定义的全局变量名称对应
kieSession.setGlobal("myGlobalList", list);
//激活规则引擎,如果匹配成功则执⾏规则
kieSession.fireAllRules();
kieSession.dispose();
System.out.println("list.size():" + list.size());
}
测试结果:

边栏推荐
- 李沐动手学深度学习V2-transformer和代码实现
- Express framework
- Interpretation of deepsort source code (I)
- Cass11.0.0.4 for autocad2010-2023 dog free usage
- deepsort源码解读(六)
- 脱氧核糖核酸DNA修饰氧化锌|DNA修饰纳米金颗粒|DNA偶联修饰碳纳米材料
- DNA modified zinc oxide | DNA modified gold nanoparticles | DNA coupled modified carbon nanomaterials
- 基于SSM图书借阅管理系统
- Netease Yunxin appeared at the giac global Internet architecture conference to decrypt the practice of the new generation of audio and video architecture in the meta universe scene
- Livox SLAM(带LIO+闭环检测优化)
猜你喜欢

采用QT进行OpenGL开发(一)绘制平面图形

Significance of NVIDIA SMI parameters

DNA coupled PbSe quantum dots | near infrared lead selenide PbSe quantum dots modified DNA | PbSe DNA QDs

DNA research experiment application | cyclodextrin modified nucleic acid cd-rna/dna | cyclodextrin nucleic acid probe / quantum dot nucleic acid probe

Introduction to the official functions of easyrecovery14 data recovery software

泛型 -- 学会它,好处多多

Boostrap

DNA修饰贵金属纳米颗粒|脱氧核糖核酸DNA修饰纳米金(科研级)

OpenGL development with QT (I) drawing plane graphics

Pytorch uses data_ Prefetcher improves data reading speed
随机推荐
Day012 一维数组的应用
Two ways of multi GPU training of pytorch
MySQL的基本语句(1)—增删改查
Gbase 8C - SQL reference 6 SQL syntax (15)
Mysql database
网易云信亮相 GIAC 全球互联网架构大会,解密新一代音视频架构在元宇宙场景的实践...
PNA modified polypeptide arms PNA PNA DNA suc aapf PNA suc - (ALA) 3 PNA
Pytorch uses data_ Prefetcher improves data reading speed
C#时间相关操作
Gbase 8C technical features
Details of cross entropy loss function in pytorch
Shell编程的规范和变量
基于SSM医院预约管理系统
CASS11.0.0.4 for AutoCAD2010-2023免狗使用方法
Student achievement management system based on SSM
Express receive request parameters
How to make the minimum API bind the array in the query string
Student status management system based on SSM
Brief introduction of simulation model
[latex format] there are subtitles side by side on the left and right of double columns and double pictures, and subtitles are side by side up and down