代码之家  ›  专栏  ›  技术社区  ›  Abhilash Muthuraj

在JavaSpring中REST方法中执行清除操作

  •  1
  • Abhilash Muthuraj  · 技术社区  · 8 年前

    我想在创建zip文件之后清理文件。其中一个操作是删除zip文件本身。

        @RequestMapping(path = "/downloadZip", method = RequestMethod.GET)
    public ResponseEntity<Resource> download(String fileName) throws IOException {
    
    //Create a zip file and add entries
    
        Path path = Paths.get(file.getAbsolutePath());
        ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path));
    
        return ResponseEntity.ok()
                .headers(headers)
                .contentLength(file.length())
                .contentType(MediaType.parseMediaType("application/octet-stream"))
                .body(resource);
    
    //Call a cleanup method
    //cleanUp();
    
    }
    

    在JUnit测试中,我可以使用静态方法删除zip文件。 课后 .

    问题 :如何定义返回后获取的方法。

    谢谢!

    1 回复  |  直到 8 年前
        1
  •  1
  •   Derrops    8 年前

    Futures @Async Controller