传值和取值

需求背景:比如说现在任务的审批人需要往下一个任务的审批人传一些值,告诉他上一个任务的审批人是谁 

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());
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值