Example #1
0
 public boolean equals(Object obj) {
   if (null == obj) return false;
   if (!(obj instanceof com.jspgou.cms.entity.ProductExt)) return false;
   else {
     com.jspgou.cms.entity.ProductExt productExt = (com.jspgou.cms.entity.ProductExt) obj;
     if (null == this.getId() || null == productExt.getId()) return false;
     else return (this.getId().equals(productExt.getId()));
   }
 }
Example #2
0
 private boolean saveImage(
     Product product, ProductExt bean, ProductType type, MultipartFile file, String uploadPath) {
   // 如果没有上传文件,则不处理。
   if (file == null || file.isEmpty()) {
     return false;
   }
   // 先删除图片,如果有的话。
   deleteImage(product, uploadPath);
   // 获得后缀
   String ext = FilenameUtils.getExtension(file.getOriginalFilename());
   // 检查后缀是否允许上传
   if (!ImageUtils.isImage(ext)) {
     return false;
   }
   // 日期目录
   String dateDir = FileNameUtils.genPathName();
   // 创建目录
   File root = new File(uploadPath, dateDir);
   // 相对路径
   String relPath = SPT + dateDir + SPT;
   if (!root.exists()) {
     root.mkdirs();
   }
   // 取文件名
   String name = FileNameUtils.genFileName();
   // 保存为临时文件
   File tempFile = new File(root, name);
   try {
     file.transferTo(tempFile);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   try {
     // 保存详细图
     String detailName = name + Product.DETAIL_SUFFIX + POINT + ext;
     File detailFile = new File(root, detailName);
     imageScale.resizeFix(
         tempFile, detailFile, type.getDetailImgWidth(), type.getDetailImgHeight());
     bean.setDetailImg(relPath + detailName);
     // 保存列表图
     String listName = name + Product.LIST_SUFFIX + POINT + ext;
     File listFile = new File(root, listName);
     imageScale.resizeFix(tempFile, listFile, type.getListImgWidth(), type.getListImgHeight());
     bean.setListImg(relPath + listName);
     // 保存缩略图
     String minName = name + Product.MIN_SUFFIX + POINT + ext;
     File minFile = new File(root, minName);
     imageScale.resizeFix(tempFile, minFile, type.getMinImgWidth(), type.getMinImgHeight());
     bean.setMinImg(relPath + minName);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   // 删除临时文件
   tempFile.delete();
   return true;
 }