Spring / Swagger,下载docx文件会生成损坏的文档。我找到了几篇类似的文章,但我没法让我的代码运行。
PDF和正常的txt文件可以正常工作。希望您能帮助我,我不知道在哪里可以找到更多信息
接口类/方法
@ApiOperation(value =“创建客户发票”,昵称=“ createBill”,notes =“使用此命令,您可以为特定的客户和月份创建发票”,标签= {“ Bill”,})< / p>
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/Bill/CreateBill/{customerid}/{month}/{year}",
produces = {"application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
method = RequestMethod.POST)
ResponseEntity<?> createBill(@ApiParam(value = "Customer number",required=true) @PathVariable("customerid") String customerid,@ApiParam(value = "Month",required=true) @PathVariable("month") Integer month,@ApiParam(value = "Year",required=true) @PathVariable("year") Integer year);
未实现的类/方法
responseHeaders.setContentType(new MediaType("application", "vnd.openxmlformats-officedocument.wordprocessingml.document"));
responseHeaders.set("Content-Disposition",
"attachment; filename=test.docx");
File file = new File("c:/temp/report.docx");
final InputStream in = new FileInputStream(file);
responseHeaders.setContentLength((int) file.length());
return ResponseEntity.ok()
.header("Content-Disposition",
"attachment; filename=docx.zip")
.contentType(new MediaType("application", "vnd.openxmlformats-officedocument.wordprocessingml.document"))
.contentLength((int) file.length())
.body(IOUtils.toByteArray(in));