@Test void uploadFile() throws Exception { String result = mockMvc.perform(multipart("/framework/file") .file(new MockMultipartFile( "file", "test.txt", MediaType.MULTIPART_FORM_DATA_VALUE, "Hello File".getBytes())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); log.info(result); }
@PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") public Result<FileInfo> uploadFile(MultipartFile file) throws IOException { FileInfo fileInfo = fileInfoService.uploadFile(file); return ResultUtil.success(fileInfo); }
FileController { @PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") public Result<FileInfo> uploadFile(MultipartFile file) throws IOException { FileInfo fileInfo = fileInfoService.uploadFile(file); return ResultUtil.success(fileInfo); } }
FileController { @PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") public Result<FileInfo> uploadFile(MultipartFile file) throws IOException { FileInfo fileInfo = fileInfoService.uploadFile(file); return ResultUtil.success(fileInfo); }  }
FileController { @PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") public Result<FileInfo> uploadFile(MultipartFile file) throws IOException { FileInfo fileInfo = fileInfoService.uploadFile(file); return ResultUtil.success(fileInfo); }  @PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") Result<FileInfo> uploadFile(MultipartFile file); @GetMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("下载文件") @PreAuthorize("isAuthenticated()") void downloadFile(@ApiParam(value = "文件id", required = true) @PathVariable String id, HttpServletResponse response) thr; @GetMapping("/log") @ApiOperation("下载服务器日志") @PreAuthorize("hasAnyRole('ADMIN')") void downloadLogFile(HttpServletResponse response); }
FileController { @PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") public Result<FileInfo> uploadFile(MultipartFile file) throws IOException { FileInfo fileInfo = fileInfoService.uploadFile(file); return ResultUtil.success(fileInfo); }  @PostMapping @ApiOperation("上传文件") @PreAuthorize("isAuthenticated()") Result<FileInfo> uploadFile(MultipartFile file); @GetMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("下载文件") @PreAuthorize("isAuthenticated()") void downloadFile(@ApiParam(value = "文件id", required = true) @PathVariable String id, HttpServletResponse response) thr; @GetMapping("/log") @ApiOperation("下载服务器日志") @PreAuthorize("hasAnyRole('ADMIN')") void downloadLogFile(HttpServletResponse response);  }