Spring boot 在Srping引导控制器中编辑映像
在编辑部分,我写了如何让它上传图像 多谢各位Spring boot 在Srping引导控制器中编辑映像,spring-boot,Spring Boot,在编辑部分,我写了如何让它上传图像 多谢各位 @PostMapping("/save") public String add(@ModelAttribute("category") Category category, RedirectAttributes ra, @RequestParam("fileImage") MultipartFile multipartFile) throws IOException {
@PostMapping("/save")
public String add(@ModelAttribute("category") Category category, RedirectAttributes ra,
@RequestParam("fileImage") MultipartFile multipartFile) throws IOException {
String fileName = StringUtils.cleanPath(multipartFile.getOriginalFilename());
category.setPhoto(fileName);
Category saveCategory = categoryService.save(category);
String uploadDir = "./category-logos/" + saveCategory.getId();
Path uploadPath = Paths.get(uploadDir);
if (!Files.exists(uploadPath)) {
Files.createDirectories(uploadPath);
}
try (InputStream inputStream = multipartFile.getInputStream()) {
Path filePath = uploadPath.resolve(fileName);
Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new IOException("could not save upload file: " + fileName);
}
return "redirect:/category/list";
}
@GetMapping("/edit/{id}")
public String edit(Model model, @PathVariable(name="id")Long id) {
//`**`**`**enter code here**`**`**`
}
你能分享这个问题的动机吗?你到底在寻找什么?搜索是在控制器中寻找修复,当控制器中有图像时,你应该编辑问题并给出更多解释。此外,你的代码格式不合适。你能分享这个问题的动机吗?你到底在寻找什么?搜索是在控制器中寻找修复,当控制器中有图像时,你应该编辑问题并给出更多解释。此外,您的代码格式不合适。