当前位置:网站首页>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());
}
测试结果:

边栏推荐
- DNA modified noble metal nanoparticles | DNA modified gold nanoparticles (scientific research level)
- deepsort源码解读(五)
- 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
- Pytorch model
- 含有偶氮苯单体的肽核酸寡聚体(NH2-TNT4,N-PNAs)齐岳生物定制
- Deepsort工作原理分析
- 仿真模型简单介绍
- Customer cases | focus on process experience to help bank enterprise app iteration
- Bert and RESNET can also be trained on mobile phones?!
- Watermelon book learning notes - Chapter 4 decision tree
猜你喜欢

AI:业余时间打比赛—挣它个小小目标—【阿里安全×ICDM 2022】大规模电商图上的风险商品检测比赛

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

What is the reason why the channel list is empty on the intelligent security video platform easycvr?

(转帖)eureka、consul、nacos的对比2

ESP8266(ESP-12F) 第三方库使用 -- SparkFun_APDS9960 (手势识别)

Basic statement of MySQL (1) - add, delete, modify and query

VIVO应用市场APP上架总结

Student achievement management system based on SSM

About the new features of ES6

手机上也能训练BERT和ResNet了?!
随机推荐
regular expression
Two ways of multi GPU training of pytorch
R2live code learning record (3): radar feature extraction
VIM editor deletes all file contents
newest! SASAC releases new measures for digital transformation of state-owned enterprises
Interpretation of deepsort source code (IV)
OpenGL development with QT (I) drawing plane graphics
Reflection on pytorch back propagation
deepsort源码解读(一)
CdS quantum dots modified DNA | CDs DNA QDs | near infrared CdS quantum dots coupled DNA specification information
Consideration on how the covariance of Kalman filter affects the tracking effect of deepsort
VScode连接远程服务器开发
About the new features of ES6
nvidia-smi 各参数意义
Day012 application of one-dimensional array
VIVO应用市场APP上架总结
Significance of NVIDIA SMI parameters
大疆livox定制的格式CustomMsg格式转换pointcloud2
2021 interview questions for php+go of Zhongda factory (2)
Working principle analysis of deepsort