vue附件上传和展示

先从后台拿到需要的数据,包括上传附件的数据以及文本数据


     
     
     
     
     
     
         
         
     
 




 
 

vue附件上传和展示_第1张图片

jsp


    


load() {
    axios.get("/fileupload/page").then((res) => {
        this.fileList=res.data;
        this.fileupload = res.data.rows;
        this.total=res.data.total
       /* this.fileList.push(res.data.rows[0].uploade[0]);*/
       /* this.fileList=res.data.rows[1].uploade;*/

        })
}

controller


@RequestMapping("/upload")
@ResponseBody
public void getUpload(@RequestParam MultipartFile file, @RequestParam String uploaddate, HttpServletRequest req) throws IOException {
    System.err.println(file.getSize() + "===" + uploaddate + file.getContentType());
    System.err.println(file.getContentType().substring(file.getContentType().lastIndexOf("/") + 1));
    System.out.println(file.getOriginalFilename());
    FileUpload upload = new FileUpload();
    //文件大小mb
    double size = file.getSize() / 1024;
    //文件类型
    String type = file.getContentType().substring(file.getContentType().lastIndexOf("/") + 1);
    //文件名字
    String filename = file.getOriginalFilename();
    String exName = FilenameUtils.getExtension(filename);
    String uuid = UUID.randomUUID().toString();
  /*  String newName = uuid + "." + exName;*/
    String newName=file.getOriginalFilename();
    String realPath = req.getServletContext().getRealPath("/upload/file");

    File file2 = new File(realPath, newName);
    File parenFile = file2.getParentFile();
    if (!parenFile.exists()) {
        parenFile.mkdirs();
    }
    file.transferTo(file2);
    upload.setUrl("/upload/file" + newName);
    upload.setFilesize(size);
    upload.setType(type);
    upload.setFileid(Long.parseLong(uploaddate));
    upload.setName(newName);

    service.save(upload);
    Long uploadId = upload.getId();
    key_upload ku = new key_upload();
    ku.setKey_id(Long.parseLong(uploaddate));
    ku.setUpload_id(uploadId);
    service.saveKU(ku);
    System.out.println("success");
}

你可能感兴趣的:(vue,vue,vue附件上传)