一、启动流程的时候设置流程变量

  1.1 案例

    /**
* 启动流程实例
*/
@Test
public void start() {
Student student=new Student();
student.setId(1);
student.setName("张三"); Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 2);
variables.put("date", new Date());
variables.put("reason", "发烧");
variables.put("student", student); ProcessInstance instance=processEngine.getRuntimeService() // 运行时Service
.startProcessInstanceByKey("StudentLeaveProcess",variables); // 流程定义表act_re_procdef的KEY字段值 System.out.println("流程实例ID:"+instance.getId());
System.out.println("流程定义ID:"+instance.getProcessDefinitionId());
}
  • 如上述例子流程启动之后,任何任务节点都可以通过excutionId获取到流程变量的值。
    /**
* 获取流程变量数据
*/
@Test
public void getVariableValues(){
RuntimeService runtimeService=processEngine.getRuntimeService();
String excutionId="52501";
Integer days=(Integer) runtimeService.getVariable(excutionId, "days");
Date date=(Date) runtimeService.getVariableLocal(excutionId, "date");
String reason=(String) runtimeService.getVariable(excutionId, "reason");
Student student=(Student) runtimeService.getVariable(excutionId, "student");
System.out.println("请假天数:"+days);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.out.println("请假对象:"+student.getId()+","+student.getName());
}

二、完成任务的时候设置流程变量

  2.1  需求

  • 在完成某个任务节点之后设置流程变量,接下来的任务节点都可以使用这个流程变量。

比如,当完成“学生请假”任务节点之后设置流程变量,然后在“班长审批”和“班主任审批”节点就可以获取该流程变量。

  2.2  案例

/**
* 完成任务
*/
@Test
public void test_completeTask2() { Student student=new Student();
student.setId(1);
student.setName("张三"); Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 2);
variables.put("date", new Date());
variables.put("reason", "发烧");
variables.put("student", student); processEngine.getTaskService().complete("62504",variables);
}
    /**
* 获取流程变量数据
*/
@Test
public void getVariableValues(){
RuntimeService runtimeService=processEngine.getRuntimeService();
String excutionId="62501";
Integer days=(Integer) runtimeService.getVariable(excutionId, "days");
Date date=(Date) runtimeService.getVariableLocal(excutionId, "date");
String reason=(String) runtimeService.getVariable(excutionId, "reason");
Student student=(Student) runtimeService.getVariable(excutionId, "student");
System.out.println("请假天数:"+days);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.out.println("请假对象:"+student.getId()+","+student.getName());
}

最新文章

  1. ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮)
  2. 导入一个AndroidStudio工程作为一个Library Module
  3. Visual Studio 2013新功能
  4. 练习2 A - ASCII码排序
  5. Java图形化界面设计——布局管理器之GridLayout(网格布局)
  6. 【NOIP2012提高组】借教室
  7. os模块介绍
  8. aarch64的架构:unrecognized command line option &#39;-mfpu=neon&#39;
  9. 二叉树的简单操作(Binary Tree)
  10. spring security 学习
  11. dom4j解析xml时取消DTD验证
  12. pom.xml文件最详细的讲解
  13. JavaWeb后台购物车类的具体实现
  14. JavaWeb开发如何用Tomcat部署发布
  15. AIX查看CPU、内存等信息
  16. 某软件大赛C#版考题整理——【多选题】
  17. 6-16 Topological Sort(25 分)
  18. Memcached 之 .NET(C#)实例分析
  19. yugabyte cloud native db 基本试用
  20. [PY3]——字典排序问题总结—(zip()函数、OrderedDict、itemgetter函数)

热门文章

  1. DIOCP任务队列和工作线程
  2. Django 测试开发2
  3. nginx php-fpm安装配置 CentOS编译安装php7.2
  4. 简易的CRM系统案例之Struts2+Hibernate3+JSP+MySQL版本
  5. SurfaceView双缓冲技术引入
  6. zip格式压缩文件辅助类(ZipHelper)
  7. python中简化的验证码功能
  8. Python - Django - 显示作者列表
  9. 【VS开发】fatal error C1853: "Debug\sift.pch"预编译头文件来自编译器的早期版本
  10. 使用Apache服务部署网站(基于IP,域名,端口)