Пример #1
0
  @RequestMapping(value = "/upload", method = RequestMethod.POST)
  public @ResponseBody void uploadProduct(
      @RequestParam(value = "pic", required = false) MultipartFile pic,
      @RequestParam(value = "id", required = false) Integer id,
      @RequestParam("name") String name,
      @RequestParam("description") String description,
      @RequestParam("type") String type,
      @RequestParam("category") String category,
      @RequestParam("price") double price,
      @RequestParam("unit") String unit,
      HttpServletResponse response) {
    if (type == null
        || name == null
        || pic == null
        || description == null
        || category == null
        || price == 0
        || unit == null) {
      response.setStatus(HttpStatus.NOT_ACCEPTABLE.value());
      return;
    }
    Product product;
    if (id != null) {
      product = productService.getById(id);
    } else {
      product = new Product();
    }
    product.setName(name);
    product.setDescription(description);
    product.setType(Type.valueOf(type));
    product.setCategory(Category.valueOf(category));
    product.setPrice(price);
    product.setUnit(unit);
    // for Linux
    String dstFilePath =
        "/" + PathUtil.getWebInfPath() + "/product_images/" + product.generatePicurlHash() + ".jpg";
    // for Windows
    //        String dstFilePath = PathUtil.getWebInfPath() + "/product_images/" +
    // product.generatePicurlHash() + ".jpg";
    System.out.println("dstFilePath =" + dstFilePath);
    if (pic != null) {
      product.setPicurl("product_images/" + product.generatePicurlHash() + ".jpg");

      File picFile = new File(dstFilePath);

      try {
        pic.transferTo(picFile);
      } catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    product.setDataChangeLastTime(new Timestamp(System.currentTimeMillis()));
    if (id != null) {
      productService.update(product);
    } else {
      productService.save(product);
    }
  }
Пример #2
0
    public Builder cursor(Cursor cursor) {
      int index;

      index = cursor.getColumnIndex(PrinterContract.DeviceCategories.UUID);
      if (index != -1) {
        uuid(cursor.getString(index));
      }
      if (uuid == null) {
        index = cursor.getColumnIndex(PrinterContract.DeviceCategories.DEVICE_UUID);
        if (index != -1) {
          uuid(cursor.getString(index));
        }
      }

      index = cursor.getColumnIndex(PrinterContract.DeviceCategories.TYPE);
      if (index != -1) {
        String t = cursor.getString(index);
        type(Type.valueOf(t));
      }

      index = cursor.getColumnIndex(PrinterContract.DeviceCategories.NAME);
      if (index != -1) {
        name(cursor.getString(index));
      }

      index = cursor.getColumnIndex(PrinterContract.DeviceCategories.MAC);
      if (index != -1) {
        mac(cursor.getString(index));
      }

      index = cursor.getColumnIndex(PrinterContract.DeviceCategories.IP);
      if (index != -1) {
        ip(cursor.getString(index));
      }

      index = cursor.getColumnIndex(PrinterContract.DeviceCategories.CATEGORY);
      if (index != -1) {
        String c = cursor.getString(index);
        category(Category.valueOf(c));
      }

      return this;
    }