Maven dependency
1 | <dependency> |
Rule Syntax
1. Conditions in Rules
A rule can contain many conditions and patterns such as:
1 | Account (balance == 200) |
The above conditions check if the Account balance is 200 or the Customer name is “Vivek”.
2. Variables in Rules
A variable name in Drools starts with a Dollar($) symbol.
1 | $account : Account( ) |
Drools can work with all the native Java types and even Enum.
3. Comments in Rules
The special characters, # or //, can be used to mark single-line comments.
For multi-line comments, use the following format:
1 | /* |
4.Functions in Rules
Functions are a convenience feature. They can be used in conditions and consequences. Functions represent an alternative to the utility/helper classes. For example:
1 | function double calculateSquare (double value) { |
5. Salience (same as priority)
Salience is a very important feature of Rule Syntax. Salience is used by the conflict resolution strategy to decide which rule to fire first. By default, it is the main criterion.
We can use salience to define the order of firing rules. Salience has one attribute, which takes any expression that returns a number of type int (positive as well as negative numbers are valid). The higher the value, the more likely a rule will be picked up by the conflict resolution strategy to fire.
1 | salience ($account.balance * 5) |
The default salience value is 0. We should keep this in mind when assigning salience values to some rules only.
参考地址
https://www.tutorialspoint.com/drools/drools_rule_syntax.htm