检验spring boot文件上传时,文件参数的检验,检验文件后缀和文件内容
例子:
@RestController
@Validated
public class TestController {
@PostMapping("/upload")
public ResponseEntity<String> uploadFile(
@ExtensionCheck(message = "not support this file extension", extensions = {"xls", "xlsx"})
@MimeTypeCheck(message = "not support this file type", mimeTypes = {"xls", "xlsx"})
MultipartFile file) {
return ResponseEntity.ok("successful");
}
}