1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| @PostMapping("/add") int add(Article article, MultipartFile file) { if (file == null || file.isEmpty()) { return 0; } String filename = file.getOriginalFilename(); String newName = UUID.randomUUID().toString().replaceAll("-", "") + filename.substring(filename.lastIndexOf(".")); try { file.transferTo(new File(this.uploadPath + newName)); } catch (IOException e) { e.printStackTrace(); } article.setPictures(newName); article.setType(1); SimpleDateFormat dateFormat = new SimpleDateFormat("yyy-MM-dd hh:mm:ss"); article.setTime(dateFormat.format(new Date())); boolean result = articleService.save(article); if (result) { return 1; } return 0; }
|