@ResponseBody
@RequestMapping("/方法名")
public AjaxMsg addUserHeadImg(HttpServletRequest request, @RequestParam("文件参数") String image,@RequestParam("其他参数") String userId){
Map<String, Object> map = new HashMap<>();
FileOutputStream fos = null;
String newFileName =UUID.randomUUID().toString()+".png";
try{
String imageName = request.getSession().getServletContext().getRealPath("/") + File.separator + “保存路径”;
byte[] buffer = new BASE64Decoder().decodeBuffer(image);
File destDir = new File(imageName);
if(!destDir.exists()) {
destDir.mkdir();
}
fos = new FileOutputStream(new File(destDir,newFileName));
fos.write(buffer);
fos.flush();
fos.close();
userService.uploadHeadImg(headImgPath+newFileName,userId);
map.put("result", 0); //返回
}catch (Exception e){
e.printStackTrace();
map.put("result", 1);
}
return AjaxMsg.success(map);
}
转载于:https://www.cnblogs.com/donotgiveup/p/8980228.html