码迷,mamicode.com
首页 > 其他好文 > 详细

文件上传action

时间:2014-07-02 17:45:14      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:blog   http   java   文件   os   art   

@RequestMapping(value = "/update.action", method = RequestMethod.POST)
	public @ResponseBody Result<AppJobProduct> update(HttpServletRequest request,@RequestParam(value = "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);
	}

 

文件上传action,布布扣,bubuko.com

文件上传action

标签:blog   http   java   文件   os   art   

原文地址:http://www.cnblogs.com/sunyt/p/3766044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!