https://blog.csdn.net/u010974598/article/details/46458039
我曾尝试了:
@RequestMapping(value="/user/register") public ModelAndView toRegister( Integer flag, User user, MultipartHttpServletRequest request, // MultipartFile file, ModelAndView mv) { if(flag == 1) { // 跳转到登录页面 System.out.println("-----去注册页面---------"); mv.setViewName("user/registerUser"); } else { // MultipartFile file = request.getParameter("file"); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> file = multipartRequest.getFiles("file"); System.out.println("处理注册! "); System.out.println(file.toString() + " ====文件啊啊啊啊 "); //上传图像: String imgpath = ImageUtil.generateNormalImg(file.get(0)); System.out.println("头像路径:" + imgpath); //添加到对象: if(imgpath != null && !imgpath.equals("")) user.setAvater(imgpath); else { System.out.println("获取图片路径失败!"); } userService.addUser(user); System.out.println("注册的用户为:" + user.toString()); mv.setViewName("redirect:/loginForm"); } return mv; }