zoukankan      html  css  js  c++  java
  • activiti7 导出bpmn文件

    最近在学习springboot+activiti7整合,想做一个导出bpmn文件的功能,查了相关资料,最后没有实现。最后查看了一下代码 找到了方法 如下所示
    @GetMapping("export")
    @Transactional
    public void export(@RequestParam("definitionId") String processInstanceId, HttpServletResponse response) {
    BufferedOutputStream bos = null;
    try {

    try {
    RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
    //
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstanceId).singleResult();
    InputStream inputStream = repositoryService
    .getProcessModel(processInstanceId);
    ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
    byte[] bpmnBytes = new byte[1024]; //buff用于存放循环读取的临时数据
    int rc = 0;
    while ((rc = inputStream.read(bpmnBytes, 0, 100)) > 0) {
    swapStream.write(bpmnBytes, 0, rc);
    }
    byte[] in_b = swapStream.toByteArray(); //in_b为转换之后的结果
    // 封装输出流
    bos = new BufferedOutputStream(response.getOutputStream());
    bos.write(in_b);// 写入流

    String filename = processDefinition.getName() + ".bpmn";
    response.setContentType("application/x-msdownload;");
    response.setHeader("Content-Disposition",
    "attachment; filename=" + filename);
    response.flushBuffer();

    } finally {
    bos.flush();
    bos.close();
    }

    } catch (Exception e) {
    System.out.println("导出文件失败");
    e.printStackTrace();
    }
    }
    其中
    InputStream inputStream = repositoryService
    .getProcessModel(processInstanceId); 可以获取bpmn文件流 直接操作导出即可
  • 相关阅读:
    Python列表去重
    hash表长度优化证明
    DDD初学指南
    继承和实现的明显区别
    微信商户支付
    centos7+mono4+jexus5.6.2安装过程中的遇到的问题
    SVN:重命名文件之后不允许提交
    SpringMVC 自定义全局日期转换器
    解决Cannot change version of project facet Dynamic web module to 2.5
    Maven项目热部署到Tomcat容器下
  • 原文地址:https://www.cnblogs.com/ggdxx/p/13397573.html
Copyright © 2011-2022 走看看