spring boot图片上传
配置限制文件上传大小 servlet: multipart: max-file-size: 5MB # 限制文件上传的大小 SpringMVC会封装为一个接口:MultipartFile @Controller @RequestMapping("upload") public class UploadController { @Autowired private UploadService uploadService; /** * 图片上传 * @param file * @return */ @PostMapping("image") public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file){ String url = this.uploadService.upload(file); if (StringUtils.isBlank(url)) { return ResponseEntity.badRequest().build(); } return ResponseEntity.status(HttpStatus.CREATED).body(url); } } 对上传的内容进行校验: 校验文件大小 校验文件的媒体类型 校验文件的内容 @Service public