首页>代码>SpringBoot整合activiti dmn规范极简入门实例 dms规范使用实例>/springboot-dmn/src/main/java/com/simon/springbootdmn/dmn/DmnDemo.java
package com.simon.springbootdmn.dmn;

import org.activiti.dmn.api.*;
import org.activiti.dmn.engine.DmnEngine;
import org.activiti.dmn.engine.DmnEngineConfiguration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Simon
 */
public class DmnDemo {

    public static void main(String[] args) {
        // 根据默认配置创建引擎的配置实例
        DmnEngineConfiguration config = DmnEngineConfiguration
                .createDmnEngineConfigurationFromResourceDefault();
        // 创建规则引擎
        DmnEngine engine = config.buildDmnEngine();
        // 获取规则的存储服务组件
        DmnRepositoryService rService = engine.getDmnRepositoryService();
        // 获取规则服务组件
        DmnRuleService ruleService = engine.getDmnRuleService();
        // 进行规则 部署
        DmnDeployment dep = rService.createDeployment()
                .addClasspathResource("dmn/first.dmn").deploy();
        // 进行数据查询
        DmnDecisionTable dt = rService.createDecisionTableQuery()
                .deploymentId(dep.getId()).singleResult();
        // 初始化参数
        Map<String, Object> params = new HashMap<>();
        params.put("personAge", 19);
        // 传入参数执行决策,并返回结果
        RuleEngineExecutionResult result = ruleService.executeDecisionByKey(
                dt.getKey(), params);
        // 控制台输出结果
        System.out.println(result.getResultVariables().get("myResult"));
        // 重新设置参数
        params.put("personAge", 5);
        // 重新执行决策
        result = ruleService.executeDecisionByKey(dt.getKey(), params);
        // 控制台重新输出结果
        System.out.println(result.getResultVariables().get("myResult"));
    }
}
最近下载更多
a1677596408  LV23 2023年4月24日
最代码官方  LV167 2023年3月12日
最近浏览更多
๑๑陌上花开  LV14 2023年9月22日
qq970040477  LV23 2023年8月28日
woldxy  LV12 2023年8月21日
muyu1dd 2023年6月29日
暂无贡献等级
dapeng0011  LV13 2023年6月19日
xxx520520  LV6 2023年5月31日
syczzxj  LV9 2023年5月30日
szf123  LV12 2023年5月30日
奋斗人生 2023年5月29日
暂无贡献等级
crosa_Don  LV18 2023年5月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友