easy-rules 规则引擎基本使用

规则引擎官网地址:https://github.com/j-easy/easy-rules

GITHUB官网Rules的Readme: https://github.com/j-easy/easy-rules/blob/master/README.md

一个朋友的源码解读:https://blog.csdn.net/u013817349/article/details/78088105

 

package cn.wcuu.test;

import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.annotation.Rule;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Action;
 
@Rule(name = "ruleValidate", description = "this is description")
public class RuleValidate {
 
    /*@Condition
    public boolean when() {
    	// condition 条件
        return true;
    }*/
    
    @Condition
    public boolean itRains(@Fact("rain") boolean rain) {
        return rain;
    }
    
    @Action
    public void then() throws Exception {
        System.out.println("validate true");
    }
 
}

package cn.wcuu.test;

import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
 
public class Start 
{
    public static void main( String[] args )
    {
    	// 初始化 facts
        Facts facts = new Facts();
        facts.put("rain", true);
        
        // 初始化rules规则
        Rules rules = new Rules();
        rules.register(new RuleValidate());
 
        // 初始化rulesEngine规则引擎,并fire启用它
        RulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.fire(rules, facts);
    }
}

以上,谢谢

 

你可能感兴趣的:(java,代码,easy-rules)