コード例 #1
0
ファイル: NavController.java プロジェクト: treejames/createsh
  @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
ファイル: PluginController.java プロジェクト: elit69/HRD_MEMO
 @RequestMapping(
     value = "/report",
     method = RequestMethod.POST,
     headers = "Accept=application/json")
 public ResponseEntity<Map<String, Object>> userReport(@RequestBody Report rp) {
   Map<String, Object> map = new HashMap<String, Object>();
   if (reportDao.saveReport(rp) == true) {
     map.put("MESSAGE", "REPORT HAS BEEN SENT");
     map.put("STATUS", HttpStatus.ACCEPTED.value());
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
   } else {
     map.put("MESSAGE", "REPORT HAS BEEN SENT FIALED");
     map.put("STATUS", HttpStatus.NOT_ACCEPTABLE.value());
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
   }
 }
コード例 #3
0
ファイル: PluginController.java プロジェクト: elit69/HRD_MEMO
 @RequestMapping(
     value = "/signup",
     method = RequestMethod.POST,
     headers = "Accept=application/json")
 public ResponseEntity<Map<String, Object>> userSignup(
     @RequestBody User user, HttpServletResponse respone) {
   Map<String, Object> map = new HashMap<String, Object>();
   if (userDao.saveUser(user) == true) {
     map.put("MESSAGE", "USER HAS BEEN SIGN UP");
     map.put("STATUS", HttpStatus.ACCEPTED.value());
     map.put("DATA", userDao.getUserByEmail(user.getEmail()));
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
   } else {
     map.put("MESSAGE", "USER SIGN UP FIALED");
     map.put("STATUS", HttpStatus.NOT_ACCEPTABLE.value());
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.NOT_ACCEPTABLE);
   }
 }