Drools 规则文件 ——语法属性

it2025-10-16  4

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

转载于:https://www.cnblogs.com/kunpengit/archive/2013/05/29/3105627.html

相关资源:数据结构—成绩单生成器
最新回复(0)