这个错误是因为没有合适的转换器将AjaxResult对象转换为multipart/form-data类型的响应。要解决这个问题,可以将返回类型改为void,并直接使用HttpServletResponse对象输出文件内容。

修改代码如下:

@PostMapping("/exportPxf")
@RequiresPermissions("manage:spcertinfo:export")
public void exportPxf(Long id, HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("utf-8");
    response.setContentType("multipart/form-data");
    response.setHeader("Content-Disposition",
            "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, certCa.getKeyName() +"-"+certCa.getVersion() + "-P10.csr"));
    FileUtils.writeBytes(pxfFile.getPath(), response.getOutputStream());
}

这样修改后,不再返回AjaxResult对象,而是直接将文件内容写入HttpServletResponse对象的输出流中。

PostMappingexportPxf RequiresPermissionsmanagespcertinfoexport ResponseBody public AjaxResult exportPxfLong id HttpServletRequest request HttpServletResponse response throws IOException

原文地址: https://www.cveoy.top/t/topic/i8vN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录