需求背景:比如说现在任务的审批人需要往下一个任务的审批人传一些值,告诉他上一个任务的审批人是谁
public void demo(){
//当前任务id为20015
String taskId = "20015";
//第一个为当前任务id,第二个为所谓的自定义标示key,第三个为value
taskService().setVariable(taskId, "name", "测试变量传递");
taskService().complete(taskId,map);
}
下一个审批人获取上一个任务传递过来的变量
public void getVariable(){
String taskid = "55003";
String name =(String) taskService.getVariable(taskid, "name");
System.out.println(name);
}
结果:
测试变量传递
但是平时我们需要的是一个对象来传递,比如申请人在页面填写申请表单,然后提交上去,这样的话我们后台传的是一个表单对象,那么对应对象怎么传值取值,其实和上面差不多,不过要注意一点就是传的对象类需要实现系列化Serializable,具体步骤如下:
第一步:创建一个表单对象
import java.io.Serializable;
public class TaskForm implements Serializable {
private static final long serialVersionUID= 8571222190258948731L;
private int day;
private String type;
private String reason;
public TaskForm(int day, String type, String reason) {
super();
this.day = day;
this.type = type;
this.reason = reason;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Override
public String toString() {
return "taskForm{" +
"day=" + day +
", type='" + type + '\'' +
", reason='" + reason + '\'' +
'}';
}
}
第二步:操作提交申请
public void completeTask(){
TaskForm taskform = new TaskForm(3, "事假", "今天老子不想上班");
String taskId = "57505";
taskService.setVariable(taskId,"taskform", taskform);
//完成任务
taskService.complete(taskId);
}
第三步:获取对象值
public void getVariable(){
String taskid = "65006";
TaskForm taskform =(TaskForm) taskService.getVariable(taskid, "taskform");
System.out.println(taskform.toString());
}