美文网首页
swagger-ui测试导出文件添加headers

swagger-ui测试导出文件添加headers

作者: lancelot123 | 来源:发表于2020-01-29 08:54 被阅读0次
swagger-ui测试导出文件添加headers
 @RequestMapping(value = "/exportReportDoc",headers="Accept=application/octet-stream")
    @ApiOperation(value = "导出word报告--1", httpMethod = "POST")
    public void exportReportDoc(@RequestBody ReportSearchForm form) {
        TestVO testVo= service.getContent(form);
        Word07Writer writer = new Word07Writer();
        // 添加段落(标题)
        writer.addText(new Font("宋体", Font.BOLD , 22), testVo.getTitle());
        // 添加段落(正文)
        writer.addText(new Font("宋体", Font.PLAIN, 18),testVo.getContent());
        for(String str : testVo.getSubContent()){
            writer.addText(new Font("宋体", Font.PLAIN, 18),str);
        }
        HttpServletResponse response = HttpContextUtils.getHttpServletResponse();
        // 写出到文件
        //writer.flush(FileUtil.file("e:/wordWrite.docx"));
        response.setCharacterEncoding("gbk");
        response.setContentType("application/ms-word");
        response.addHeader("Content-Disposition", "attachment; filename=\"report-"+ String.valueOf(System.currentTimeMillis()).substring(4, 13) + "\".doc");
        try {
            writer.flush(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.close();
    }

相关文章

网友评论

      本文标题:swagger-ui测试导出文件添加headers

      本文链接:https://www.haomeiwen.com/subject/ledvthtx.html