当前位置:网站首页>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:12501See 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,,,zhangsanThe 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,,,zhangsanThe 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,,,zhangsanSame 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
请假原因:faShaoThe 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,,,zhangsanThe 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
边栏推荐
猜你喜欢

基于MindSpore高效完成图像分割,实现Dice!

NowCoderTOP35-40——持续更新ing

MySQL事务

How can project cost control help project success?

IDEA performs the Test operation, resulting in duplicate data when data is inserted

DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从

气象数据数据处理实例——matlab字符串切割匹配与R语言日期匹配(数据拼接)

Common operations of oracle under linux and daily accumulation of knowledge points (functions, timed tasks)

Tanabata romantic date without overtime, RPA robot helps you get the job done

Microservice Technology Stack
随机推荐
[Android]如何使用RecycleView in Kotlin project
入门 Polkadot 平行链开发,看这一篇就够了
FPGA:基础入门按键控制LED灯
PHP operation mangoDb
MySQL advanced (twenty-seven) database index principle
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
PCB布局必知必会:教你正确地布设运算放大器的电路板
第四章:activiti RuntimeService设置获和取流程变量,及与taskService的区别,开始和完成任务时设置流程变量[通俗易懂]
【翻译】混沌网+SkyWalking:为混沌工程提供更好的可观察性
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
第七章,activiti个人任务分配,动态指定和监听器指定任务委派人「建议收藏」
第五章:多线程通信—wait和notify
数据中台建设(十):数据安全管理
LeetCode 216. Combined Sum III (2022.08.04)
egg框架使用(二)
【 temperature warning program DE development 】 event driven model instance
js hijacks the array push method
SD NAND Flash简介!
Data Middle Office Construction (10): Data Security Management