1, the basic matching rules
1.1 Variables
Drools uses the matching method to compare the fact,
such as Java code account:account (Balance > 100)
The meaning of this rule is to find all account instances with the type account in fact and the balance property value greater than 100.
You can specify a variable to describe a type or a property that maps a class.
For example, Java code $account: Account ($type: type)
Use $variable to define a variable, where two variables are defined, $account represents a variable that defines a type account, and $type maps the type attribute in the account type. Variables are defined to be used in subsequent rules. Java Code $account: account (Balance >100) Customer (account = = $account)
This is to find some fact of the custom type, and its account attribute must meet the balance>100 conditions previously defined.
1.2 Types
Drools supports a variety of Java data types
String : Strings Java code Customer (name = = "John")
Regular expression:
Java code Customer (name matches "[a-z][a-z]+")
Indicates that the Name property of the customer type must satisfy the first letter A-Z, and that the second digit has one or more lowercase a-Z.
Date : Day type Java Code account (Datecreate > "01-feb-2009")
The format of the date is "dd-mmmm-yyyy" by default and can be changed.
Boolean: Boolean type Java code Transaction (isapprove = = True)
enum: Enum type Java code account (type = = Account.Type.STUDENT)
1.3 Notes
Single-line Comment://or #
Multi-line Comment:/*/
1.4-Pack Java code Package Com.kingsun.drools.rules
Declaring the package to which the rule file belongs is a namespace organization, similar to the Java package, where there is no physical need for a corresponding directory structure, it is just a logical division.
1.5 Import
Imports can import the classes used in the rule, or import the externally defined Functiong Java code Import java.util.Map that is used in the rule; Import Com.kingsun.drools.service.LegacyBankService.extractData;
When importing a method, this method must be static because the static import attribute of the jdk1.5 is used.
1.6 Globally variable Global
declaring a global variable Java code Global reportfactory reportfactory;
assigning values to global variables Java code session.setglobal ("Reportfactory", reportfactory);
or Java code list<command> commands = new arraylist<command> (); Commmands.add (Commandfactory.newsetglobal ("Reportfactory", reportfactory));
using global Variables Java code session.getglobals ();
1.7 function functions
A function can be defined in a rule file, but more by using the static method defined in the outer class, so that as long as the logic in Java can be implemented, it can be invoked as a function in the rule.
The functiong of calling an external class needs to be aware that the method must be static, statically, and that the class can be defined in the Help helper class.
The external class requires import, and the parameter types used in the function also require import.
For example, set a static method in an external Validationhelper helper class Java code public static double Calculateaccount + account.balance * 1.2; }