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);
}
转载请注明原文地址: https://ju.6miu.com/read-1311391.html