JBPM学习(五):流程变量

最近发现这篇文章挺多人看的,也挺多人有疑问,我很想帮你们解答,但是很无奈,这篇文章只是我当时在自学时看的一个教程的记录,当时对JBPM也没有深入去学习,并且到现在也已经快4年了,这期间我都没用过JBPM,因此JBPM的东西我也忘得差不多了。庆幸的是我把当时看的教程保存了下来,因此如果对此文章有疑问的可以直接看JBPM的教程。另外,通过我分享的视频大家也能看到这是一个OA教程,我当时刚入门自学Java时就看过这个教程,这是一个使用Spring+Struts 2 +Hibernate框架搭建OA的教程,我自己觉得是一个很不错的教程,讲师的声音很好听,听了让人很舒服,特别适合新手。因此如果你想要关于这个OA教程的其他内容,可以关注我的公众号【程序员囧辉】,发送【资料】自行获取,不仅有JBPM、OA,还有各种BAT一线大厂面试题,自学教程等资料。

 

作者更新于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. 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员囧辉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值