首页 > 代码库 > 文件上传action

文件上传action

@RequestMapping(value = "http://www.mamicode.com/update.action", method = RequestMethod.POST)	public @ResponseBody Result<AppJobProduct> update(HttpServletRequest request,@RequestParam(value = "http://www.mamicode.com/upload", required = false) MultipartFile file,@ModelAttribute AppJobProduct appJobProduct) {		if(file!=null){		String filename=new Date().getTime()+"."+StringUtils.substringAfterLast(file.getOriginalFilename(), ".");		String path=request.getSession().getServletContext().getRealPath("product_image");		File tFile=new File(path,filename);		appJobProduct.setProductImageLink(/*request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+*/request.getContextPath()+"/product_image/"+filename);		if(!tFile.exists()){			tFile.mkdir();		}		try {			file.transferTo(tFile);		} catch (IllegalStateException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (IOException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		}		return this.appJobProductService.update(appJobProduct);	}