activiti 流程设计器 示例 源码
https://download.csdn.net/download/anysun7/10354206
src/main/resources目录下新建spring-activiti.xml文件,向其中加入以下内容
xml version="1.0" encoding="UTF-8"?>
<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.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
bean>
<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
bean>
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<bean id="identityService" factory-bean="processEngine"
factory-method="getIdentityService" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
bean>
beans>
在web.xml文件,修改context-param,添加了classpath:spring-activiti.xml
下载activiti-webapp-explorer2的源代码,
1. 将activiti-explorer工程中的diagram-viewer,editor-app和modeler.html复制到工程的src/main/webapp目录下
2. 将activiti-explorer工程中WEB-INF/classes文件夹下的stencilset.json,ui.properties,ui.properties.alfresco复制到工程的src/main/resources目录下
3.modules/目录中找到org\activiti\rest\diagram和org\activiti\rest\editor这两个包,将他们整个复制到工程的src/main/java目录下
4.修改spring-mvc.xml文件,在其中加入以下内容,使spring在扫描controller类的时候,也扫描这些包里面的类
5.向工程的web.xml文件中添加以下内容,让spring也管理起来带/service/的链接
<servlet-mapping>
<servlet-name>springMvcservlet-name>
<url-pattern>/service/*url-pattern>
servlet-mapping>
6.打开editor-app/app-cfg.js, 将其中的“activiti-explorer”修改为“jeecg”。当然,具体项目中这里可能会经常变化,我们可以写一个js函数来自动获取工程的名字,这样以后将设计器集成到其他工程的时候,就不需要修改这里的内容了
7.工程的src\main\java\org\activiti\rest\editor目录下新建一个java文件,命名为ModuleController
package org.activiti.rest.editor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Model;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.core.common.controller.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@Controller
@RequestMapping("/model")
public class ModuleController extends BaseController{
private Logger logger = LoggerFactory.getLogger(ModuleController.class);
@Autowired
private RepositoryService repositoryService;
@RequestMapping(params = "create")
public void create(HttpServletRequest request, HttpServletResponse response) {
try {
String name = "test";
String key = "test";
String description = "testModel";
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode editorNode = objectMapper.createObjectNode();
editorNode.put("id", "canvas");
editorNode.put("resourceId", "canvas");
ObjectNode stencilSetNode = objectMapper.createObjectNode();
stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
editorNode.put("stencilset", stencilSetNode);
Model modelData = repositoryService.newModel();
ObjectNode modelObjectNode = objectMapper.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
description = StringUtils.defaultString(description);
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName(name);
modelData.setKey(StringUtils.defaultString(key));
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" + modelData.getId());
} catch (Exception e) {
logger.error("创建模型失败:", e);
}
}
}
8. 访问:http://localhost:8080/jeecg/model.do?create
新版(3.7.2)jeecg中response的处理,添加了org.jeecgframework.core.aop.Wrapper,导致json数据返回解析出错。整合时,需处理。
Jeecg修改pom内容
Maven版本改为 5.18.0
添加:
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>2.2.3version>
dependency>
Springmvc添加 (rest请求数据 /jeecg/service/model/5001/json)
TypeError: Cannot read property 'split' of undefined
at Object.ORYX.Core.StencilSet.stencilSet (oryx.debug.js:8647)解决思路:遇到该错误,主要原因是后台返回json数据时,格式存在问题,请查看response中最终返回到页面之前的数据。查看是否是框架对数据做了处理,寻找相应解决方法。
https://blog.csdn.net/fgstudent/article/details/50668086