首页  

easyrules 例子 基于注解     所属分类 easyrules 浏览量 190
easyrules 4.1.0



import org.jeasy.rules.annotation.Action; import org.jeasy.rules.annotation.Condition; import org.jeasy.rules.annotation.Fact; import org.jeasy.rules.annotation.Rule; import org.jeasy.rules.api.Facts; @Rule(name = "age rule", description = "Check if user is of legal age to buy alcohol") public class AgeRule { @Condition public boolean checkAge(@Fact("age") int age) { System.out.println("age="+age); return age >= 18; } @Action public void action(Facts facts) { System.out.println("age is >= 18"); facts.put("result","age is >= 18"); } @Priority public int getPriority() { return 1;} }
import org.jeasy.rules.api.Facts; import org.jeasy.rules.api.Rules; import org.jeasy.rules.core.DefaultRulesEngine; public class AgeRuleDemo { public static void main(String[] args) { AgeRule ageRule = new AgeRule(); Rules rules = new Rules(); rules.register(ageRule); DefaultRulesEngine rulesEngine = new DefaultRulesEngine(); Facts facts = new Facts(); facts.put("age", 20); facts.put("name", "tiger"); // [main] DEBUG org.jeasy.rules.core.DefaultRulesEngine - Rule 'age rule' triggered rulesEngine.fire(rules, facts); System.out.println(facts); facts = new Facts(); facts.put("age", 10); // [main] DEBUG org.jeasy.rules.core.DefaultRulesEngine - Rule 'age rule' has been evaluated to false, it has not been executed rulesEngine.fire(rules, facts); System.out.println(facts); } }
注解 @Rule(name = "age rule", description = "Check if user is of legal age to buy alcohol") @Priority @Fact("age") int age @Action(order = 0) @Action(order = 1) 多个 action

上一篇     下一篇
OOM kill 监控

grafana 图表 变量

easyrules 简介

easyrules 例子 从 nacos里读取规则

统计学术语

apache math库计算 z值表