Camunda工作流集成SpringBoot(四)

节点之间的参数传递

书接上回Camunda工作流集成SpringBoot(三)
业务场景:还是一条请假申请,总不能没有请假的理由,直接申请到领导那里请求领导批示吧,所以在工作流之间参数的传递怎么做呢

TaskService

setVariable和setVariableLocal

区别:前者全局,后者只能本节点使用

//如果是职员任务节点需要提交任务参数
if(task.getAssignee().equals("zhangsan")) {
            /** 1.使用基本数据类型设置流程变量 **/
           	taskService.setVariableLocal(task.getId(), "请假天数", 3); // 与任务ID绑定
            
            taskService.setVariable(task.getId(), "请假日期", new Date());
            
            taskService.setVariable(task.getId(), "请假原因", "回家养病,大概一周把!");
            
            User user = new User();
         	
         	user.setId(10);
         	
         	user.setName("小红");
         	//实体类需要实现序列化接口
         	taskService.setVariable(task.getId(), "用户信息", user);
			//执行请假申请的上报
			taskService.complete(task.getId())
        }

getVariable

//如果是经理的任务节点则获取上报的任务参数
if(task.getAssignee().equals("jack")){

	       Integer days = (Integer) taskService.getVariable(task.getId(), "请假天数"); //null
	 
            Date date = (Date) taskService.getVariable(task.getId(), "请假日期");
            
            String comment = (String) taskService.getVariable(task.getId(), "请假原因");
            
            User user =(User)taskService.getVariable(task.getI(),"用户信息");
            
            System.out.println("请假天数:" + days + "\n 请假日期:" + date + "\n 请假原因:" + comment +"\n 用户信息:" +user);

}

总结

佛系更新中…

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
你可以按照以下步骤将Camunda工作流集成Spring Boot项目中: 1. 添加Camunda依赖:在项目的pom.xml文件中添加Camunda依赖。你可以根据需要选择特定的Camunda版本,例如: ```xml <dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter</artifactId> <version>7.15.0</version> </dependency> ``` 2. 配置Camunda:在Spring Boot项目的application.properties或application.yml文件中添加以下Camunda相关配置: ```properties # 数据库配置 spring.datasource.url=jdbc:h2:mem:camunda;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE spring.datasource.username=sa spring.datasource.password= spring.datasource.driver-class-name=org.h2.Driver # Camunda配置 spring.jpa.database-platform=org.hibernate.dialect.H2Dialect camunda.bpm.database.schema-update=true # Camunda REST API配置(可选) camunda.bpm.rest.enabled=true camunda.bpm.rest.authentication-enabled=false ``` 上述配置使用了内存数据库H2,你可以根据需要选择其他数据库,并相应地修改配置。 3. 创建工作流定义:在项目的resources目录下创建一个`.bpmn`或`.bpmn20.xml`文件来定义工作流程。你可以使用Camunda Modeler等工具进行图形化编辑,也可以手动编写XML。 4. 编写服务类:创建一个Java类来定义Camunda服务。你可以使用`@Component`、`@Service`或`@RestController`等注解将该类注册为Spring Bean,并实现所需的工作流逻辑。 5. 启动应用程序:编写一个启动类(例如,添加了`@SpringBootApplication`注解的类),以启动Spring Boot应用程序。 完成以上步骤后,你的Spring Boot应用程序将集成Camunda工作流引擎,并可使用工作流定义和自定义服务类来执行工作流程。 注意:以上步骤提供了一个基本的集成示例,你可以根据实际需求进行调整和扩展。有关更多详细信息和高级配置,请参考CamundaSpring Boot的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

商朝

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

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

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

打赏作者

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

抵扣说明:

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

余额充值