解决 springboot 上传头像后台接收 MultipartFile 为 null 问题

springboot 参数上传需要加注解类型识别

错误示范(该方式获取 MultipartFile  为null ):

@ApiOperation(value = "设置用户头像", notes = "设置当前用户头像")
@RequestMapping(value = "/profiles", method = RequestMethod.POST)
public Object setUserProfile(MultipartFile profile,HttpServletRequest request) {
   String userid = request.getParameter("userId");
   return service.updUserProfile(profile,userid);
}

正确的方式要加上  @RequestParam("file"),表明该参数类型是文件类型

@ApiOperation(value = "设置用户头像", notes = "设置当前用户头像")
@RequestMapping(value = "/profiles", method = RequestMethod.POST)
public Object setUserProfile(@RequestParam("file") MultipartFile profile,HttpServletRequest request) {
   String userid = request.getParameter("userId");
   return service.updUserProfile(profile,userid);
}

 

 

你可能感兴趣的:(springboot,文件上传)