(九)Activitivi5之使用 RuntimeService 設置和獲取流程變量


一、案例

  /** 
   * 設置流程變量數據 */ @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 設置/獲取變量的方法跟(八)Activiti之流程變量和局部流程變量不同的是,流程變量綁定的是任務ID,如下圖
  • 而RuntimeService綁定的是act_ru_execution表的executionId。任務ID隨着任務節點的變化而變化,而executionId一般不會改變。

  • 同樣,用RuntimeService設置的值同樣在接下來的流程都可以獲取,知道流程結束

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM