1.查询数据库pdf文件并浏览器预览
@GetMapping("/download/report/{equipNo}")
@Log(value = "下载报告", type = LogType.SELECT)
public void downLoadReportFile(@PathVariable String equipNo, HttpServletRequest request, HttpServletResponse response) {
Service.downLoadReportFile(equipNo, request, response);
}
@Transactional(rollbackFor = Exception.class)
public void downLoadReportFile(String equipNo, HttpServletRequest request, HttpServletResponse response) {
//先获取文件信息
//传输
Path reportPdf = CoreFileUtils.getLocalPath(coreFile);
File newPdf = reportPdf.toFile();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline;fileName=pageNo.pdf");
try {
FileInputStream inputStream = new FileInputStream(newPdf);
OutputStream os = response.getOutputStream();
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = inputStream.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}