当前位置:网站首页>Chapter 4: In the activiti process, variable transmission and acquisition process variables, setting and acquiring multiple process variables, setting and acquiring local process variables "recommende
Chapter 4: In the activiti process, variable transmission and acquisition process variables, setting and acquiring multiple process variables, setting and acquiring local process variables "recommende
2022-08-05 10:19:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
In the previous chapter we introduced the deployment process example,启动流程,查看任务,完成任务的service和实例,Let's introduce how to get the variables that need to be passed in the process.
开始前,First run through the task node name and task delegate of the process:
流程图如上,The three task node names are respectivelyleave001,leave002,leave003,因为我的NavicatCan't read the Chinese characters in the process, so it can be simply understood as three leave processes,请假001,请假002,请假003.
Then look at the task delegators:
分别是xiaoliu001,xiaoliu002,xiaoliu003;
好了,Let's start to introduce the transfer of process variables:
承接上一章:
/**
* Set process variable data
*/
@Test
public void setVariableValues(){
TaskService taskService=processEngine.getTaskService();//获取任务
String taskId="";//more tasksidknow which character it is,设置流程变量.You can view the tasks in more ways to view tasksid,You can look directly at the database
//Set the content of the task below,比如请假流程,The first node of the task is the reason why the applicant wants to write a condolence
taskService.setVariable(taskId, "days", 2);//请假天数
taskService.setVariable(taskId, "date", new Date());//请假日期
taskService.setVariable(taskId, "reason", "发烧");//请假原因
//Now let's test an additional knowledge point,It is the process transfer variable,这里我们再新建一个student对象,对象有id 和name两个属性,There is also serialized transmission
Student student=new Student();
student.setId(1);
student.setName("zhangsan");
taskService.setVariable(taskId, "student",student);//序列化对象
}
The above is to set process variables.
Get the process variables below:
/**
* Get process variable data
*/
@Test
public void getVariableValues(){
TaskService taskService=processEngine.getTaskService();//获取任务
String taskId="";
Integer day=(Integer) taskService.getVariable(taskId, "days");//获取请假天数
Date date=(Date) taskService.getVariable(taskId, "date");//请假日期
String reason=(String) taskService.getVariable(taskId, "reason");//请假原因
Student student2=(Student) taskService.getVariable(taskId, "student");//序列化对象
System.out.println("请假天数:"+day);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.err.println("Subject to leave:"+student2.getId()+",,,"+student2.getName());
}
然后,The process is started,Before starting we open the database first,可以先看看act_ru_task任务表,此时没有任务,This table should be empty.
Start the process below:
this runsstart方法:
At this point, the task table has a piece of data,
Then execute the view task method,Check out the tasksid:
结果如下:
任务ID:12504
任务名称:leave001
任务创建时间:Sun Apr 22 12:40:52 CST 2018
task assigner:xiaoliu001
任务流程实例Id:12501
See also the task listID_字段值.
Then put this value into the method we just wrote to set the process variable:
、
执行上面的方法,After success we look at the databaseact_ru_variableThe table will have several variables that we set:
然后我们继续往下走,Execute the complete task method,Be careful to modify the taskid哦
After the completion of the task arrivedleave002节点,
Here we look directly at the task of the dataid是多少:
17502,Then we have this taskidTo execute the method we just wrote to get the process variable:
执行结果是:
请假天数:2
请假日期:Sun Apr 22 12:47:58 CST 2018
请假原因:faShao
Subject to leave:1,,,zhangsan
The result is the value we put in.说明没问题.
Then execute the completion method,流程到leave003任务节点,Then get the process variable data.
结果:
请假天数:2
请假日期:Sun Apr 22 12:47:58 CST 2018
请假原因:faShao
Subject to leave:1,,,zhangsan
The same can be obtained.
最后再complete完成方法,Finish the process,流程结束:
The task list is cleared.
Here's another way to set multiple variables:
/**
* Set multiple process variable data
*/
@Test
public void setVariableValue1(){
TaskService taskService=processEngine.getTaskService();//获取任务
String taskId="25004";//more tasksidknow which character it is,设置流程变量.You can view the tasks in more ways to view tasksid,You can look directly at the database
//Set the content of the task below,比如请假流程,The first node of the task is the reason why the applicant wants to write a condolence
// taskService.setVariable(taskId, "days", 2);//请假天数
// taskService.setVariable(taskId, "date", new Date());//请假日期
// taskService.setVariable(taskId, "reason", "faShao");//请假原因
//Now let's test an additional knowledge point,It is the process transfer variable,这里我们再新建一个student对象,对象有id 和name两个属性,There is also serialized transmission
Student student2=new Student();
student2.setId(1);
student2.setName("zhangsan");
taskService.setVariable(taskId, "student",student2);//序列化对象
Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 3);
variables.put("date",new Date());
variables.put("reason", "faShao2");
variables.put("student", student2);
taskService.setVariables(taskId, variables);
}
/**
* Get multiple process variable data
*/
@Test
public void getVariableValue(){
TaskService taskService=processEngine.getTaskService();//获取任务
String taskId="25004";
Map<String, Object> variables=taskService.getVariables(taskId);
Integer day=(Integer) variables.get("days");//获取请假天数
Date date=(Date) variables.get("date");//请假日期
String reason=(String) variables.get("reason");//请假原因
Student student2=(Student) variables.get("student");//序列化对象
System.out.println("请假天数:"+day);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.err.println("Subject to leave:"+student2.getId()+",,,"+student2.getName());
}
The testing process is the same as before,The final result obtained is:
请假天数:3
请假日期:Sun Apr 22 13:09:22 CST 2018
请假原因:faShao2
Subject to leave:1,,,zhangsan
Same as set.
Next, we introduce another local variable,That is, the set variable value is only valid in the current node,When the process goes to the next node,This value cannot be obtained.
/**
* Set process local variable data
*/
@Test
public void setVariableLocalValue(){
TaskService taskService=processEngine.getTaskService();//获取任务
String taskId="25004";//more tasksidknow which character it is,设置流程变量.You can view the tasks in more ways to view tasksid,You can look directly at the database
//Set the content of the task below,比如请假流程,The first node of the task is the reason why the applicant wants to write a condolence
taskService.setVariableLocal(taskId, "days", 2);//请假天数
taskService.setVariable(taskId, "date", new Date());//请假日期
taskService.setVariable(taskId, "reason", "faShao");//请假原因
//Now let's test an additional knowledge point,It is the process transfer variable,这里我们再新建一个student对象,对象有id 和name两个属性,There is also serialized transmission
Student student=new Student();
student.setId(1);
student.setName("zhangsan");
taskService.setVariable(taskId, "student",student);//序列化对象
}
/**
* Get process variable data
*/
@Test
public void getVariableLocalValues(){
TaskService taskService=processEngine.getTaskService();//获取任务
String taskId="32502";
Integer day=(Integer) taskService.getVariableLocal(taskId, "days");//获取请假天数
Date date=(Date) taskService.getVariable(taskId, "date");//请假日期
String reason=(String) taskService.getVariable(taskId, "reason");//请假原因
Student student2=(Student) taskService.getVariable(taskId, "student");//序列化对象
System.out.println("请假天数:"+day);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.err.println("Subject to leave:"+student2.getId()+",,,"+student2.getName());
}
This code value changes the value of the number of days off,并使用了setVariablesLocal()方法.Run the set local process variable method first,It is found that the variable table of the database will have an additional data of the number of days of leave:
Then execute the get method:
Subject to leave:1,,,zhangsan
请假天数:2
请假日期:Sun Apr 22 13:24:02 CST 2018
请假原因:faShao
The number of days off is2Overrides another value in the database for leave days.然后执行complete()method to complete the task.
Execute the get method again,结果:
请假天数:null
请假日期:Sun Apr 22 13:24:02 CST 2018
请假原因:faShao
Subject to leave:1,,,zhangsan
The number of days of leave has become empty.
The variable table of the database is also missing a piece of data.
好了,This is the process local variable.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106144.html原文链接:https://javaforall.cn
边栏推荐
- QSS 选择器
- PHP 操作mangoDb
- 机器学习-基础知识 - Precision, Recall, Sensitivity, Specificity, Accuracy, FNR, FPR, TPR, TNR, F1 Score, Bal
- 电竞、便捷、高效、安全,盘点OriginOS功能的关键词
- 第四章:activiti流程中,变量的传递和获取流程变量 ,设置和获取多个流程变量,设置和获取局部流程变量「建议收藏」
- Oracle temporary table space role
- 教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!
- STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
- three.js调试工具dat.gui使用
- 企业的数字化转型到底是否可以买来?
猜你喜欢
Custom filters and interceptors implement ThreadLocal thread closure
NowCoderTOP35-40 - continuous update ing
入门 Polkadot 平行链开发,看这一篇就够了
2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing
Ali's new launch: Microservices Assault Manual, all operations are written out in PDF
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
High-quality DeFi application building guide to help developers enjoy DeFi Summer
Microcontroller: temperature control DS18B20
three objects are arranged in a spherical shape around the circumference
如何选币与确定对应策略研究
随机推荐
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
你最隐秘的性格在哪?
阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
Score interview (1)----related to business
第七章,activiti个人任务分配,动态指定和监听器指定任务委派人「建议收藏」
Custom filters and interceptors implement ThreadLocal thread closure
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
uniapp connect ibeacon
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
多线程(进阶) - 2.5w字总结
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
Go编译原理系列6(类型检查)
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
QSS 选择器
Jenkins manual (2) - software configuration
力扣(LeetCode)216. 组合总和 III(2022.08.04)
数据中台建设(十):数据安全管理
High-quality DeFi application building guide to help developers enjoy DeFi Summer
FPGA: Use of the development environment Vivado