public void download(HttpServletResponse response) throws IOException { TbRiskUnit pojo= new TbRiskUnit(); CurrentLoginUser user = AppUtil.getCurrentUser(); if (user.getUserType() == 2) { pojo.setCorpId(user.getCorpId()); } List<TbRiskUnit> list = unitService.getQrCodeList(pojo); String[] filePath = new String["D:\\tomcat\\tomcat-9.0.65_risk\\webapps\\"+list.size()]; StringBuilder sb=new StringBuilder(); List<File> fileList = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { TbRiskUnit qrCode = list.get(i); sb.append(qrCode.getImageUrl()).append(","); fileList.add(new File(qrCode.getImageUrl())); } response.setHeader("content-type", "application/octet-stream"); response.setContentType("application/octet-stream"); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=download.zip"); ZipUtils.downloadZip(response.getOutputStream(), fileList); }这段代码的作用
时间: 2024-03-19 19:42:45 浏览: 69
这段代码的作用是从服务器上获取一些风险单位的二维码图片,并将这些图片打包成zip文件,然后通过HttpServletResponse将zip文件下载到本地。具体实现过程是通过调用unitService的getQrCodeList方法获取风险单位的信息,然后通过遍历获取的信息将每个二维码图片的文件路径添加到fileList中,最后使用ZipUtils工具类将fileList中的文件打包成zip文件,并通过HttpServletResponse将zip文件下载到本地。
阅读全文