if(null!=file&&file.exists())file.delete();
}
}
private ProductImage fileUpload(MultipartHttpServletRequest multipartRequest,String key){
Map<String,MultipartFile> maps = multipartRequest.getFileMap();
MultipartFile file = maps.get(key);
try {
if(null==file)return null;
String name = file.getOriginalFilename();
if(null==name||"".equals(name.trim()))return null;
String[] names = name.split("\\"+System.getProperty("file.separator"));
name = names[names.length-1];
names = name.split("\\.");
name = names[names.length-2];
ProductImage productImage = new ProductImage();
productImage.setDate(new Date());
productImage.setDescription(name);
name = productImage.getDate().getTime()+"";
productImage.setName(name);
String uploadPath = ImageUtils.getUploadPath();
String sourcePath = uploadPath + System.getProperty("file.separator") + name+".jpg";
file.transferTo(new File(sourcePath));
String[] path = sourcePath.split("\\"+System.getProperty("file.separator"));
sourcePath = path[path.length-3]+"/"+ path[path.length-2]+"/"+ path[path.length-1];
productImage.setSourceURL(sourcePath);
return productImage;