(9)Activitivi5之使用 RuntimeService 设置和获取流程变量

本文介绍了在Activiti中如何设置和获取流程变量,包括整型、日期、字符串和自定义对象类型的变量。通过RuntimeService进行操作,变量可以在流程的整个生命周期内被访问,直到流程结束。示例代码详细展示了设置和获取变量的方法,对于理解和使用Activiti的流程变量管理具有指导意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。

目录

概 述

第一种方法:设置流程变量

/** 
   * 设置流程变量数据
     */
    @Test
    public void setVariableValues(){
        RuntimeService runtimeService=processEngine.getRuntimeService(); // 任务Service
        String executionId="90001";
        runtimeService.setVariable(executionId, "days", 2);
        runtimeService.setVariable(executionId, "date", new Date());
        runtimeService.setVariable(executionId, "reason", "发烧");
        Student student=new Student();
        student.setId(1);
        student.setName("张三");
        runtimeService.setVariable(executionId, "student", student); // 存序列化对象
    }

/**
* 获取流程变量数据
*/
@Test
public void getVariableValues(){
RuntimeService runtimeService=processEngine.getRuntimeService(); // 任务Service
String executionId=“102501”;
Integer days=(Integer) runtimeService.getVariable(executionId, “days”);
Date date=(Date) runtimeService.getVariable(executionId, “date”);
String reason=(String) runtimeService.getVariable(executionId, “reason”);
Student student=(Student) runtimeService.getVariable(executionId, “student”);
System.out.println(“请假天数:”+days);
System.out.println(“请假日期:”+date);
System.out.println(“请假原因:”+reason);
System.out.println(“请假对象:”+student.getId()+","+student.getName());
}

分析:

小结

:而RuntimeService绑定的是act_ru_execution表的executionId。任务ID随着任务节点的变化而变化,而executionId一般不会改变。

同样,用RuntimeService设置的值同样在接下来的流程都可以获取,知道流程结束
通过Activiti 流程部署方式 activi 动态部署,请大家指正~

参考资料和推荐阅读

1.链接: 参考资料.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

迅捷的软件产品制作专家

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

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

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

打赏作者

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

抵扣说明:

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

余额充值