private File headImg; //文件接收
private String headImgContentType; // 图像类型
private String headImgFileName; // 图像名称
if(headImg != null){
// 1、保存图像到upload/user
String filePath = ServletActionContext.getServletContext().getRealPath("upload/user");
// 2、获取保存路径的绝对值
String fileName = UUID.randomUUID().toString().replace("-", "")+ headImgFileName.substring(headImgFileName.lastIndexOf(".")) ;
// 3、复制文件
FileUtils.copyFile(headImg, new File(filePath,fileName));
// 4、设置用户头像路径
user.setHeadImg("user/"+fileName);
}
userService.save(user);
}