博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Drools 规则文件 ——语法属性
阅读量:6857 次
发布时间:2019-06-26

本文共 1264 字,大约阅读时间需要 4 分钟。

1.
salience 
功能:设置规制执行的优先级
值:数字(
数字越大执行优先级越高)
示例:
rule "rule1" 
 
salience
  when 
eval(true) 
  then  
System.out.println("rule1");
end 
 
2.
no-loop
功能:控制已经执行的规则条件再次满足是否再次执行
值:
true/
false
示例:
rule "rule1" 
 
no-loop true 
  when 
  $customer:Customer(name=="张三") 
  then  
   update($customer); 
  System.out.println("customer name:"+$customer.getName()); 
  End
 
3.
activation-group
功能:若干个规则划分成一个组
值:分组名称
 
示例:
rule "rule2"
 
activation-group "test"
 salience 10 
 when
  eval(true)
  then
    System.out.println("rule2 execute");
 end
 
 rule "rule1"
 
activation-group "test"
 salience 9
 when
 eval(true)
 then
 System.out.println("rule1 execute");
end 
 
note:
如果同一组规则,谁的salience高就执行谁,没有则按顺序执行最后同组最后那个规则
 
 
 
4.
declare
作用:
Drools除了可以接受用户在外部向 WorkingMemory当中插入现成的
Fact对象,还允许用户在规则文件当中定义一个新的 Fact对象。
 
语法:
declare Address
熟悉名 : 类型
end
 
示例:
package com.demo.fact
 
declare Address
city : String
addressName : String
end
 
rule "rule1"
salience 2
when
eval(true);
then 
Address add = new Address();
add.setCity("中国上海");
add.setAddressName("中国上海松江区");
insert(add);
end
 
 
5.
date-expires
功能:当系统时间<=date-expires后才会触发
值:日期默认格式为
dd-MMM-yyyy
可以设置其它时间格式如
yyyy-MM-dd,
需在代码设置系统时间格式System.setProperty("drools.dateformat", "yyyy-MM-dd");
 
示例:
rule "rule1" 
 
date-expires "2009-09-27" 
  when 
  eval(true); 
  then  
  System.out.println("rule1 is execution!");  
  end 
   

转载地址:http://ctjyl.baihongyu.com/

你可能感兴趣的文章
linux 安装 node
查看>>
“不劳而获”的数字货币真的存在么?
查看>>
k8s拾遗 - Secret
查看>>
Android SparseArray 原理解析
查看>>
PHP类的定义
查看>>
Composer 中国镜像地址配置
查看>>
比特币暴跌后的连锁反应
查看>>
Python爬虫入门教程 62-100 30岁了,想找点文献提高自己,还被反爬了,Python搞起,反爬第2篇...
查看>>
第80节:Java中的MVC设计模式
查看>>
区块链100讲:以实例形式深入浅出讲透BANCOR算法
查看>>
Java并发编程 深入剖析volatile关键字
查看>>
java生成MD5校验码及算法实现
查看>>
thymeleaf 学习笔记(转)
查看>>
Mac 升级 OpenSSL
查看>>
Python学习笔记(5)-if判断、if嵌套、判断小练习
查看>>
文本转换成音频流
查看>>
负载均衡之lvs
查看>>
C#之类与对象知识点
查看>>
斯坦福大学公开课机器学习:Neural network-model representation(神经网络模型及神经单元的理解)...
查看>>
七、集成swagger2
查看>>