当前位置:网站首页>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
边栏推荐
- 机器学习-基础知识 - Precision, Recall, Sensitivity, Specificity, Accuracy, FNR, FPR, TPR, TNR, F1 Score, Bal
- Pytorch Deep Learning Quick Start Tutorial -- Mound Tutorial Notes (3)
- FPGA: Basic Getting Started LED Lights Blinking
- 深入理解 Istio 流量管理的超时时间设置
- STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
- SD NAND Flash简介!
- Custom filters and interceptors implement ThreadLocal thread closure
- MySQL之数据视图
- 上位机开发C#语言:模拟STC串口助手接收单片机发送数据
- Tanabata romantic date without overtime, RPA robot helps you get the job done
猜你喜欢
项目成本控制如何帮助项目成功?
创建一个 Dapp,为什么要选择波卡?
登录功能和退出功能(瑞吉外卖)
5. Deploy the web project to the cloud server
Egg framework usage (1)
NowCoderTOP35-40 - continuous update ing
Open Source Summer | How OpenHarmony Query Device Type (eTS)
2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing
如何选币与确定对应策略研究
产品太多了,如何实现一次登录多产品互通?
随机推荐
Can MySQL use aggregate functions without GROUP BY?
Microservice Technology Stack
Jenkins使用手册(2) —— 软件配置
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
攻防世界-PWN-new_easypwn
【Unity】【UGUI】【在屏幕上显示文本】
Ali's new launch: Microservices Assault Manual, all operations are written out in PDF
PCB布局必知必会:教你正确地布设运算放大器的电路板
QSS 选择器
What is the function of the regular expression replaceAll() method?
Pycharm 常用外部工具
Oracle 19.3 restart 环境
IDEA performs the Test operation, resulting in duplicate data when data is inserted
FPGA:开发环境Vivado的使用
你最隐秘的性格在哪?
用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战
static linking and dynamic linking
上位机开发C#语言:模拟STC串口助手接收单片机发送数据
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy