Does the DROOLS - the rule engine can be used?

xiaoxiao2021-03-06  43

All projects are exhausted by demand changes, and Extreme Program provides philosophical, an attitude, but more practical, and is those technologies that can deal with demand. For example, use OLAP to support the fast customization of complex reports, with Script language such as Groovy to support customer custom formula, and Rule Engine, we hang a dear business rule on the mouth.

Rule Engine's meaning: 1. Complex IF ... Else .... elseif is sorted into a clear rule of one article 2. Separate business rules from program logic 3. If the rule changes, no need to recompile and deploy the system. 4. If Rule Engine provides a normal user-level rule language, you can directly let the customer's domain experts regulate rules.

Rule Engine is not fresh, and Drools must be pro-people than other rule engines, using Java and XML, allowing the rule engine to enter all program groups as JSP. First look at a streamlined and practical HelloWorld, consisting of two parts, one is Test.jsp of calling rules:

/ / Set a test for VO

Vo vo = new vo ();

Vo.SetPostatus ("A: Draft");

// Read the rules

Rulebase rulebase = rulebasebuilder.buildfromurl ("rule.drl");

// put the VO in WorkingMemory and execute

WorkingMemory WorkingMemory = rulebase.newwminingmemory ();

WorkingMemory.AssertObject (vo);

Workingmemory.fireAllRules ();

//Show results

Out.print (Po.getPostatus ());

One is the rule file rule.drl:

com.ito.vo

Vo.getStatus (). Equals ("A: Draft")

Vo.setStatus ("B: Order");

The entire rules are divided into three sections, and the first paragraph defines the object just put into; the second paragraph uses Java syntax judgment conditions; the third paragraph is the implementation statement when the conditions are met.

It's really simple.

转载请注明原文地址:https://www.9cbs.com/read-60210.html

New Post(0)