在初识drools中对drl文件进行了简单的介绍。这里举个例子来具体说明下。主要是写了规则之后我们如何用java代码来run起来。
drl文件内容如下:
rule "ageUp12" when
$student: Student(age > 2)
then
$student.ageUp12();
end
rule "nameMax" when
$student: Student(name == "max")
then
$student.nameMax();
retract($student);
end
rule "class" when
$student:Student()
then
$student.toString();
retract($student);
end
rule "testList" when
$student : Student($age : age)
not Student(age < $age)
then
System.out.println("age = " + $age);
retract($student);//这里导致了LHS的变化 然后会重新触发规则的匹配慎用 这里只是为了展示排序的例子,然后这个rule可以排序。。。。
end
我们在文件中import了一个Student类,代码很简单,就是一个javaBean,里面有两个字段:int age和String name;然后还有几个方法