JBPM学习(五):流程变量

简介: 本文主要讲流程变量

最近发现这篇文章挺多人看的,也挺多人有疑问,我很想帮你们解答,但是很无奈,这篇文章只是我当时在自学时看的一个教程的记录,当时对JBPM也没有深入去学习,并且到现在也已经快4年了,这期间我都没用过JBPM,因此JBPM的东西我也忘得差不多了。庆幸的是我把当时看的教程保存了下来,因此如果对此文章有疑问的可以直接看JBPM的教程。另外,通过我分享的视频大家也能看到这是一个OA教程,我当时刚入门自学Java时就看过这个教程,这是一个使用Spring+Struts 2 +Hibernate框架搭建OA的教程,我自己觉得是一个很不错的教程,讲师的声音很好听,听了让人很舒服,特别适合新手。



作者更新于2020-06-04




1.启动流程实例


// 启动流程实例
@Test
public void startProcessInstance() {
  // 使用指定key的最新版本的流程定义启动流程实例
  ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
  System.out.println("processInstanceId=" + pi.getId());
}




2.设置流程变量

a) 一个设置流程变量实例


//设置流程变量
@Test
public void setVariable() {
  String executionId = "test.140001";
  String name = "请假天数";
  Integer value = 3;
  //将name为"请假天数",value=3的流程变量设置到executionId为test.140001的执行对象上
  processEngine.getExecutionService().setVariable(executionId, name, value);
}


b) 所有设置流程变量方法


用到变量的类型:

 

Object value = "";
String executionId = "";
String taskId = "";
String name = "";
String processDefinitionKey = "";
String variableName = "";
Set<String> variableNames = new HashSet<String>();
Map<String, Object> variablesMap = new HashMap<String, Object>();

具体方法:



// 根据Execution设置一个流程变量
processEngine.getExecutionService().setVariable(executionId, name, value);
// 根据Execution设置多个流程变量(需要先把流程变量放到一个Map中)
processEngine.getExecutionService().setVariables(executionId, variablesMap);
// 根据Task设置多个流程变量(需要先把流程变量放到一个Map中,通过Task方法,它会先找到它所属的Execution然后设置流程变量)
processEngine.getTaskService().setVariables(taskId, variablesMap);
// 使用指定key的最新版本的流程定义启动流程实例,并设置一些流程变量
processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey, variablesMap);
// 办理完指定的任务,并设置一些流程变量
processEngine.getTaskService().completeTask(taskId, variablesMap);

3.获取流程变量

a) 一个获取流程变量实例



//获取流程变量
@Test
public void getVariable() {
  String executionId = "test.140001";
  String variableName = "请假天数";
  //从executionId为test.140001的执行对象上取出流程变量名为"请假天数"的流程变量的value
  Integer value = (Integer) processEngine.getExecutionService().getVariable(executionId, variableName);
  System.out.println(variableName + " = " + value);
}


b) 所有获取流程变量方法

用到变量的类型:



String executionId = "";
String taskId = "";
String variableName = "";
Set<String> variableNames = new HashSet<String>();


具体方法:



// 根据Execution获取指定名称的一个流程变量
processEngine.getExecutionService().getVariable(executionId, variableName);
// 根据Execution获取所有流程变量的名称
processEngine.getExecutionService().getVariableNames(executionId);
// 根据Execution获取指定名称的所有流程变量
processEngine.getExecutionService().getVariables(executionId, variableNames);
// 根据Task获取指定名称的一个流程变量
processEngine.getTaskService().getVariable(taskId, variableName);
// 根据Task获取所有流程变量的名称
processEngine.getTaskService().getVariableNames(taskId);
// 根据Task获取指定名称的所有流程变量
processEngine.getTaskService().getVariables(taskId, variableNames);


4.流程变量所支持的值的类型(jBPM User Guide,7.2. Variable types)

jBPM supports following Java types as process variables:



  • java.lang.String
  • java.lang.Long
  • java.lang.Double
  • java.util.Date
  • java.lang.Boolean
  • java.lang.Character
  • java.lang.Byte
  • java.lang.Short
  • java.lang.Integer
  • java.lang.Float
  • byte[] (byte array)
  • char[] (char array)
  • hibernate entity with a long id
  • hibernate entity with a string id
  • serializable


For persistence of these variable, the type of the variable is checked in the order of this list. The first match will determine how the variable is stored.  


相关文章
|
XML 缓存 数据格式
12activiti - 流程管理定义(设计流程定义文档)
12activiti - 流程管理定义(设计流程定义文档)
146 0
|
存储 数据库
13activiti - 流程管理定义(部署流程定义)
13activiti - 流程管理定义(部署流程定义)
79 0
|
9月前
基于jeecgboot的flowable流程按照条件进行流转的例子
基于jeecgboot的flowable流程按照条件进行流转的例子
210 1
|
数据库
23activiti - 流程变量(流程图)
23activiti - 流程变量(流程图)
58 0
29activiti - 流程变量(总结)
29activiti - 流程变量(总结)
86 0
25activiti - 流程变量(设置和获取流程变量)
25activiti - 流程变量(设置和获取流程变量)
69 0
27activiti - 流程变量(查询历史的流程变量)
27activiti - 流程变量(查询历史的流程变量)
87 0
26activiti - 流程变量(模拟流程变量的设置和获取的场景)
26activiti - 流程变量(模拟流程变量的设置和获取的场景)
48 0
24activiti - 流程变量(启动流程实例)
24activiti - 流程变量(启动流程实例)
44 0
|
SQL 存储 数据库
Flowable 设置流程变量的四种方式
Flowable 设置流程变量的四种方式
1249 0

热门文章

最新文章