@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);
}
原文地址:http://www.cnblogs.com/sunyt/p/3766044.html