Drools规则文件的语法属性详解编程语言

1.salience 
功能:设置规制执行的优先级
值:数字(数字越大执行优先级越高)
示例:
rule "rule1" 
  salience 1 
  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 
注意:
如果同一组规则,谁的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 

Drools规则文件的语法属性详解编程语言

转载请注明来源网站:blog.ytso.com谢谢!

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/14824.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论