package droolsDemo // Description: Each drl must declare a package name, the package name with different Java inside, and it does not require the same hierarchy of folders, // can be mainly used to specify which file to load .drl according to kmodule.xml different package properties, //packages="org.some.pkg "represents ksession2 only loads the file under the rules of org.some.pkg, if I did not write, the default file to load all the rules. // Import entity class import com.qianxin.rulesengine.drools.User import com.qianxin.rulesengine.drools.Pet import com.qianxin.rulesengine.drools.Dog import com.qianxin.rulesengine.drools.BoolTest rule "multiple condition" // salience larger values first match salience 1 when A plurality of condition test @: user in age between 15-3060-90 and logic to handle different color pet according to the attribute of a user, $user : User((age>15 && age<30)||(age>60 && age<90)) $pet : Pet() from $user.pet if($pet.getColor()=="black") do[black] // do after the end of the key, continue to follow the logic, the end of the program after the end of the break keyword if($pet.getColor()=="white") break[white] then System.out.print ( "end of the test"); then [black] System.out.println("pet color is balck"); then [white] System.out.print("pet color is white"); end rule "BigInteger test" salience 20 when // BigInteger can be resolved relatively (over 64) in large numbers to support the direct use of> = == = <symbol direct comparison, very convenient // development can be used to solve a relatively IPv6 $dog : Dog(age=="21262780079976241822035969236715638783") then System.out.println ( "I am equal to 21262780079976241822035969236715638783"); end rule "string compare" salience -20 when / * String of numbers is comparable * / $user : User((age>"15" && age<"40")||(age>"60")) then System.out.println ( "My priority is -20"); // This rule no longer match after match other rules drools.halt(); end rule "test bool " salience 100 when // even if value is a boolean type, so you can also compare $bool : BoolTest(value=="true") then System.out.println("I am true"); end rule "test contains and not contains" salience 200 when // contains and not contains the contents of the collection can be tested $user : User(set contains "360") then System.out.println ( "test showed comprising 360"); end rule "test not in" salience 100 when // test not in line with the age is not between 15-3060-90 $user : User(!((age>15 && age<30)||(age>60 && age<90))) then System.out.print ( "age is not between 15-30,60-90"); end rule "number test" when $user : User(age>15 && age<60) then System.out.println ( "age-qualified"); end rule "String test" when $pet : Pet(name=="cat") then System.out.println ( "qualified pet name"); end
More detailed syntax, please refer to: http://www.1994july.club/seo/