最近在研究JBPM工作流引擎,发现JBPM是基于Drools的,官方文档查看得知Drools是一款规则引擎。兴趣之下,仔细了解了下 Drools,Drools作为JBoss出品的一款开源推理和规则引擎,被广泛的应用在各个领域,如JBPM也是基于Drools的。一般我们使用规则 引擎的前提和场景是:业务规则频繁变化!如果业务规则稳定则无需应用规则引擎的,实际中诸如移动通信商、银行等领域则广泛的使用了规则引擎,主要是为了适 应频繁变更的规则,但又不需要影响业务逻辑代码。

在看了官方的一些文档介绍后,通过一个例子体验了下Drools,例子说明如下:

1、小明手上有50元钱;

2、1元钱可以买一瓶饮料;

3、2个空瓶可以兑换一瓶饮料;

4、问题是:最终小明可以喝多少瓶饮料;

通过Drools的规则推理引擎可以很好的解决这类问题,至于搭建Drools的开发环境就不细说了。直接上代码说明:

一、规则fact

 1 package com.nonbankcard.drools.jisuan;
 2 /**
 3  * 事实
 4  * @author sxf
 5  *
 6  */
 7 public class User {
 8       private int money; // 手中的钱
 9       private int kp; // 空瓶数
10       private int totals; // 喝掉的瓶数
11     public int getMoney() {
12         return money;
13     }
14     public void setMoney(int money) {
15         this.money = money;
16     }
17     public int getKp() {
18         return kp;
19     }
20     public void setKp(int kp) {
21         this.kp = kp;
22     }
23     public int getTotals() {
24         return totals;
25     }
26     public void setTotals(int totals) {
27         this.totals = totals;
28     }
29       
30       
31 }
View Code

相关文章:

  • 2021-11-10
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2021-09-07
  • 2021-12-22
  • 2021-10-07
相关资源
相似解决方案