首页 > 代码库 > 【Activiti-02】 基本操作
【Activiti-02】 基本操作
1.创建系统需要的25张数据表;
配置数据库连接
activiti.cfg.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl" /> <property name="jdbcDriver" value="oracle.jdbc.driver.OracleDriver" /> <property name="jdbcUsername" value="activiti" /> <property name="jdbcPassword" value="activiti" /> <property name="databaseSchemaUpdate" value="true" /> <!-- <property name="jobExecutorActivate" value="http://www.mamicode.com/false" /> --> <!-- <property name="mailServerHost" value="http://www.mamicode.com/mail.my-corp.com" /> --> <!-- <property name="mailServerPort" value="http://www.mamicode.com/5025" /> --> </bean> </beans>
import java.util.ArrayList; import java.util.List; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.ProcessEngines; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.task.Task; public class Test { public static void main(String[] args) { Test t = new Test(); // t.buildProcessEngine(); // t.deploy(); // t.runTime(); // t.getTask(); // t.complete(); } //获得默认的流程引擎 ProcessEngine pe = ProcessEngines.getDefaultProcessEngine(); /** * #5、完成任务 */ public void complete(){ TaskService taskService = pe.getTaskService(); List<Task> tasklist = this.getTask(); taskService.complete(tasklist.get(0).getId()); } /** * #4、获得任务 */ public List<Task> getTask(){ List<Task> tasklist = new ArrayList<Task>(); String assignee = "liusu"; TaskService taskService = pe.getTaskService(); tasklist = taskService.createTaskQuery() .taskAssignee(assignee) .list(); for(Task task:tasklist){ System.out.println(task.getName()); System.out.println(task.getId()); System.out.println("-------------"); } return tasklist; } /** * #3、启动一个流程 */ public void runTime(){ String processKey = "myProcess"; RuntimeService runtimeService = pe.getRuntimeService(); runtimeService.startProcessInstanceByKey(processKey); } /** * #2、部署一个 流程 */ public void deploy(){ RepositoryService repositoryService = pe.getRepositoryService();//获得Service repositoryService.createDeployment()//创建部署对象 .addClasspathResource("bpmn/mainBpmn.bpmn") .addClasspathResource("bpmn/mainBpmn.png") .name("测试流程") .deploy();//部署 } /** * #1、创建流程引擎 */ public void buildProcessEngine(){ //活的流程引擎配置信息 ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault(); //创建流程引擎 processEngineConfiguration.buildProcessEngine(); } }
运行后、数据库会生成25张数据表
【Activiti-02】 基本操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。