当前位置 : 主页 > 编程语言 > java >

springboot上传下载

来源:互联网 收集:自由互联 发布时间:2021-06-28
下载 /** * 下载 pdf * @param id * @param table * @return */ @RequestMapping("/donloadpdf") @ResponseBody public ResponseEntity donloadpdf( String id ,String table ) { logger.info("donloadpdf 进入web开始下载 pdf"); try { String pdf
下载
/**
     *  下载 pdf
     * @param id
     * @param table
     * @return
     */
    @RequestMapping("/donloadpdf")
    @ResponseBody
    public ResponseEntity
 
   donloadpdf( String id ,String  table )  {
        logger.info("donloadpdf 进入web开始下载 pdf");
        try {
            String pdfpath = null;
            if ("notice".equals(table)){
                TfLawNotice notice = (TfLawNotice) queryID(id).get(0);
                 pdfpath = notice.getPdfpath();
            }else if("sued".equals(table)){
                TfLawSued sued = (TfLawSued) querySuedID(id).get(0);
                pdfpath =  sued.getPdfpath();
            }
            File file = new File(pdfpath);
            HttpHeaders headers = new HttpHeaders();
            String filename = new String(file.getName().getBytes("utf-8"), "ISO-8859-1");
            headers.setContentDispositionFormData("attachment",filename );
            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
            logger.info("donloadpdf  结束下载 pdf");
            return new ResponseEntity
  
   (FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); } catch (Exception e) { e.printStackTrace(); } return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); }
  
 
上传
/* springboot  上传
       
          @RequestParam("pdfpath") MultipartFile file,
       
            file.transferTo(new File(path));*/
网友评论