注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建
1.maven导包,这里就没有什么多的好说了,直接代码:
junit
junit
4.11
org.springframework
spring-beans
4.0.9.RELEASE
org.springframework
spring-core
4.0.9.RELEASE
org.springframework
spring-aop
4.0.9.RELEASE
org.springframework
spring-context
4.0.9.RELEASE
org.springframework
spring-webmvc
4.0.9.RELEASE
org.springframework
spring-web
4.0.9.RELEASE
org.springframework
spring-aspects
4.0.9.RELEASE
org.springframework
spring-expression
4.0.9.RELEASE
org.springframework
spring-tx
4.0.9.RELEASE
javax.servlet
javax.servlet-api
3.1.0
com.fasterxml.jackson.core
jackson-annotations
2.2.3
com.fasterxml.jackson.core
jackson-core
2.2.3
com.fasterxml.jackson.core
jackson-databind
2.2.3
org.activiti
activiti-modeler
5.16
org.activiti
activiti-engine
5.16
org.activiti
activiti-explorer
5.16
org.activiti
activiti-rest
5.16
org.springframework
spring-context-support
4.0.9.RELEASE
mysql
mysql-connector-java
5.1.34
org.activiti
activiti-spring
5.16
org.springframework
spring-jdbc
4.0.9.RELEASE
org.springframework
spring-test
4.0.9.RELEASE
org.activiti
activiti-bpmn-converter
5.16
org.codehaus.jackson
jackson-core-asl
1.9.11
org.codehaus.jackson
jackson-mapper-asl
1.9.11
2.基础配置:web.xml,这个也主要是spring相关的东西,不多说了:
字符集过滤器
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
字符集编码
encoding
UTF-8
encodingFilter
/*
RestletServlet
org.restlet.ext.servlet.ServerServlet
org.restlet.application
org.activiti.rest.editor.application.ModelerRestApplication
RestletServlet
/service/*
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring.xml
springMVC
*.do
activiti.html
activiti.htm
activiti.jsp
default.html
default.htm
default.jsp
text/html;charset=utf-8
package model;
import java.util.Date;
public class ActivitiModel {
private String id;
private String name;
private String key;
private String description;
private Date createTime;
private Date lastUpdateTime;
private int version;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "ActivitiModel [id=" + id + ", name=" + name + ", key=" + key
+ ", description=" + description + ", createTime=" + createTime
+ ", lastUpdateTime=" + lastUpdateTime + ", version=" + version
+ "]";
}
}
5.后台业务代码,这里最后的操作是把跳转到acitiviti-modeler流程图设计界面的路径返回到了前端,然后让前端再跳转到流程图设计界面。
在我操作过程中,必须这样做才能实现设想的结果,因为我的前端使用的是angular js,页面上的路由跳转也都是由angular ui来控制,所以像第一篇spring整合activiti-modeler中那样从后台直接重定向的话就没有任何反应:
/**
* 创建模型
*
* @author:tuzongxun
* @Title: create
* @param @param activiti
* @param @param request
* @param @param response
* @param @return
* @return Object
* @date Mar 17, 2016 12:30:29 PM
* @throws
*/
@RequestMapping(value = "/create.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public Object create(@RequestBody ActivitiModel activiti,
HttpServletRequest request, HttpServletResponse response) {
Map map = new HashMap();
Boolean isLogin = this.isLogin(request);
if (isLogin) {
Model newModel = repositoryService.newModel();
try {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode modelObjectNode = objectMapper.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME,
activiti.getName());
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION,
StringUtils.defaultString(activiti.getDescription()));
newModel.setMetaInfo(modelObjectNode.toString());
newModel.setName(activiti.getName());
newModel.setKey(StringUtils.defaultString(activiti.getKey()));
repositoryService.saveModel(newModel);
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);
repositoryService.addModelEditorSource(newModel.getId(),
editorNode.toString().getBytes("utf-8"));
} catch (Exception e) {
e.getStackTrace();
}
// response.sendRedirect(request.getContextPath() +
// "/service/editor?id="
// + newModel.getId());
map.put("isLogin", "yes");
map.put("userName",
(String) request.getSession().getAttribute("userName"));
map.put("path", "/service/editor?id=");
map.put("modelId", newModel.getId());
} else {
map.put("isLogin", "no");
}
return map;
}
(1).app.js:
$stateProvider
.state('create', {
url: "/create",
views: {
'view': {
templateUrl: 'activi_views/create.html',
controller: 'createCtr'
}
}
});
angular.module('activitiApp')
.controller('createCtr', ['$rootScope','$scope','$http','$location','$state', function($rootScope,$scope,$http,$location,$state){
//创建模型
$http.post("createFlush.do").success(function(result){
if(result.isLogin==="yes"){
$rootScope.userName=result.userName;
}else{
$location.path("/login");
}
});
$scope.createTo=function(activiti){
//向后台提交数据
$http.post("./create.do",activiti,{headers:'Content-Type:application/json'}).success(function(createResult){
console.log(createResult);
$location.path("/modelList");
window.open("http://localhost:8080/activitiTest1"+createResult.path+createResult.modelId);
});
}
}])
[退出登陆]
当前登陆用户:{
{userName}}
(4).create.html:
创建模型
Name :
Key :
Description:
7.如果模型创建成功,则可以看到数据库act_re_model中会出现一条数据,如下:
同时在act_ge_bytearray表中会出现两条数据,如下图:
并且可以看到,在model表中会有两个字段把bytearray表中两条数据的id保存起来。