当前位置: 首页>編程日記>正文

idea项目中使用URule 规则引擎的简单例子

idea项目中使用URule 规则引擎的简单例子

如需转载分享,请标明出处,且不用于盈利为目的,谢谢合作!   

                                                        idea项目中使用URule 规则引擎的简单例子

 

简介

URule是一款纯Java规则引擎,它以RETE算法为基础,提供了向导式规则集、脚本式规则集、决策表、交叉决策表(PRO版提供)、决策树、评分卡及决策流共六种类型的规则定义方式,配合基于WEB的设计器,可快速实现规则的定义、维护与发布。

URule提供了两个版本:一个是基于Apache-2.0协议开源免费版本,URule开源版本第一款基于Apache-2.0协议开源的中式规则引擎;另一个是商用PRO版本,点击http://www.bstek.com 了解更多关于URule商用Pro版更多信息。

URULE PRO版与开源版主要功能比较

特性

URULE PRO版

URULE开源版

向导式决策集

脚本式决策集

决策树

决策流

决策表

交叉决策表

复杂评分卡

文件名、项目名重构

参数名、变量常量名重构

Excel决策表导入

规则集模版保存与加载

中文项目名和文件名支持

服务器推送知识包到客户端功能的支持

知识包优化与压缩的支持

客户端服务器模式下大知识包的推拉支持

规则集中执行组的支持

规则流中所有节点向导式条件与动作配置的支持

循环规则多循环单元支持

循环规则中无条件执行的支持

导入项目自动重命名功能

规则树构建优化

对象查找索引支持

规则树中短路计算的支持

规则条件冗余计算缓存支持

基于方案的批量场景测试功能

知识包调用监控

更为完善的文件读写权限控制

知识包版本控制

SpringBean及Java类的热部署

技术支持

SpringBoot项目中使用(最新版本2.1.7)

项目结构:

  1. 在pom.xml中添加依赖:
    <dependency><groupId>com.bstek.urule</groupId><artifactId>urule-console</artifactId><version>2.1.7</version>
    </dependency>

     

  2. 在yml中添加:
    server:port: 9999
    urule:repository:dir: d:/urulerepo

     

  3. 启动类上添加:
    @SpringBootApplication
    @ImportResource({"classpath:urule-console-context.xml"})

     

  4. IndexServlet类
    package com.bdqn.cn.config;import com.bdqn.cn.entity.Customer;
    import com.bstek.urule.ClassUtils;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.File;
    import java.io.IOException;/*** @author sunhao* @since */
    public class IndexServlet extends HttpServlet {private static final long serialVersionUID = 9155627652423910928L;@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.sendRedirect(req.getContextPath()+"/urule/frame");}public static void main(String[] args) {File file=new File("d:/customer.xml");ClassUtils.classToXml(Customer.class, file);}
    }

     

  5. PropertiesConfiguration类
    package com.bdqn.cn.config;import com.bstek.urule.URulePropertyPlaceholderConfigurer;
    import org.springframework.beans.factory.InitializingBean;import java.util.Properties;/*** @author sunhao* @since*/
    //@Component
    public class PropertiesConfiguration extends URulePropertyPlaceholderConfigurer implements InitializingBean {@Overridepublic void afterPropertiesSet() throws Exception {Properties props=new Properties();props.setProperty("urule.repository.xml", "classpath:mysql.xml");  setProperties(props);}
    }

     

  6. URuleServletRegistration类
    package com.bdqn.cn.config;import com.bdqn.cn.test.MethodTest;
    import com.bstek.urule.console.servlet.URuleServlet;
    import org.springframework.boot.web.servlet.ServletRegistrationBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.stereotype.Component;import javax.servlet.http.HttpServlet;/*** @author sunhao* @since*/
    @Component
    public class URuleServletRegistration {@Beanpublic ServletRegistrationBean<HttpServlet> registerURuleServlet(){return new ServletRegistrationBean<HttpServlet>(new URuleServlet(),"/urule/*");}@Beanpublic ServletRegistrationBean<HttpServlet> registerIndexServlet(){return new ServletRegistrationBean<HttpServlet>(new IndexServlet(),"/");}@Beanpublic MethodTest methodTest(){return new MethodTest();}
    }

     

  7. Customer类
    package com.bdqn.cn.entity;import com.bstek.urule.model.Label;
    import lombok.Data;import java.util.Date;@Data
    public class Customer {@Label("名称")private String name;@Label("年龄")private int age;@Label("出生日期")private Date birthday;@Label("等级")private int level;@Label("手机号")private String mobile;@Label("性别")private boolean gender;@Label("是否有车")private boolean car;@Label("婚否")private boolean married;@Label("是否有房")private boolean house;
    }

     

  8. MethodTest类
    package com.bdqn.cn.test;import java.text.SimpleDateFormat;
    import java.util.Date;import com.bdqn.cn.entity.Customer;
    import com.bstek.urule.action.ActionId;
    import com.bstek.urule.model.ExposeAction;
    /*** @author sunhao*/
    public class MethodTest {@ActionId("helloKey")public String hello(String username){System.out.println("hello "+username);return "hello"+username;}@ExposeAction("方法1")public boolean evalTest(String username){if(username==null){return false;}else if(username.equals("张三")){return true;}return false;}@ExposeAction("测试Int")public int testInt(int a,int b){return a+b;}public int testInteger(Integer a,int b){return a+b*10;}@ExposeAction("打印内容")public void printContent(String username,Date birthday){SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");if(birthday!=null){System.out.println(username+"今年已经"+sd.format(birthday)+"岁了!");}else{System.out.println("Hello "+username+"");}}@ExposeAction("打印Member")public void printUser(Customer m){System.out.println("Hello "+m.getName()+", has house:"+m.isHouse());}
    }

     

  9. 运行访问UI地址
    http://localhost:9999/urule/frame 

    附: d盘下的customer.xml

<?xml version="1.0" encoding="utf-8"?><variables clazz="com.bdqn.cn.entity.Customer"><variable name="age" label="年龄" type="Integer" act="InOut"/><variable name="birthday" label="出生日期" type="Date" act="InOut"/><variable name="car" label="是否有车" type="Boolean" act="InOut"/><variable name="gender" label="性别" type="Boolean" act="InOut"/><variable name="house" label="是否有房" type="Boolean" act="InOut"/><variable name="level" label="等级" type="Integer" act="InOut"/><variable name="married" label="婚否" type="Boolean" act="InOut"/><variable name="mobile" label="手机号" type="String" act="InOut"/><variable name="name" label="名称" type="String" act="InOut"/>
</variables>

 


https://www.fengoutiyan.com/post/15277.html

相关文章:

  • idea 自定义依赖
  • vue公共方法
  • idea点击方法进入实现类
  • idea vue开发
  • idea导入依赖包
  • 流程引擎和规则引擎
  • cep规则引擎
  • 规则引擎对比
  • 鏡像模式如何設置在哪,圖片鏡像操作
  • 什么軟件可以把圖片鏡像翻轉,C#圖片處理 解決左右鏡像相反(旋轉圖片)
  • 手機照片鏡像翻轉,C#圖像鏡像
  • 視頻鏡像翻轉軟件,python圖片鏡像翻轉_python中鏡像實現方法
  • 什么軟件可以把圖片鏡像翻轉,利用PS實現圖片的鏡像處理
  • 照片鏡像翻轉app,java實現圖片鏡像翻轉
  • 什么軟件可以把圖片鏡像翻轉,python圖片鏡像翻轉_python圖像處理之鏡像實現方法
  • matlab下載,matlab如何鏡像處理圖片,matlab實現圖像鏡像
  • 圖片鏡像翻轉,MATLAB:鏡像圖片
  • 鏡像翻轉圖片的軟件,圖像處理:實現圖片鏡像(基于python)
  • canvas可畫,JavaScript - canvas - 鏡像圖片
  • 圖片鏡像翻轉,UGUI優化:使用鏡像圖片
  • Codeforces,CodeForces 1253C
  • MySQL下載安裝,Mysql ERROR: 1253 解決方法
  • 勝利大逃亡英雄逃亡方案,HDU - 1253 勝利大逃亡 BFS
  • 大一c語言期末考試試題及答案匯總,電大計算機C語言1253,1253《C語言程序設計》電大期末精彩試題及其問題詳解
  • lu求解線性方程組,P1253 [yLOI2018] 扶蘇的問題 (線段樹)
  • c語言程序設計基礎題庫,1253號C語言程序設計試題,2016年1月試卷號1253C語言程序設計A.pdf
  • 信奧賽一本通官網,【信奧賽一本通】1253:抓住那頭牛(詳細代碼)
  • c語言程序設計1253,1253c語言程序設計a(2010年1月)
  • 勝利大逃亡英雄逃亡方案,BFS——1253 勝利大逃亡
  • 直流電壓測量模塊,IM1253B交直流電能計量模塊(艾銳達光電)
  • c語言程序設計第三版課后答案,【渝粵題庫】國家開放大學2021春1253C語言程序設計答案
  • 18轉換為二進制,1253. 將數字轉換為16進制
  • light-emitting diode,LightOJ-1253 Misere Nim
  • masterroyale魔改版,1253 Dungeon Master
  • codeformer官網中文版,codeforces.1253 B
  • c語言程序設計考研真題及答案,2020C語言程序設計1253,1253計算機科學與技術專業C語言程序設計A科目2020年09月國家開 放大學(中央廣播電視大學)
  • c語言程序設計基礎題庫,1253本科2016c語言程序設計試題,1253電大《C語言程序設計A》試題和答案200901
  • 肇事逃逸車輛無法聯系到車主怎么辦,1253尋找肇事司機