Xóa bài viết
Bạn có chắc chắn muốn xóa bài viết này không ?
Xóa bình luận
Bạn có chắc chắn muốn xóa bình luận này không ?
Your TIL title
Your TIL title
content
TranTrongY 13-08-2020
Xin chào mọi người
Hôm nay mình có làm chút Crud products của spring boot Và trong lúc làm mình có 1 vấn đề nhỏ đó là Trong project controller mình viết 1 method edit nhưng mình truyền tham số và edit lại nó lỗi or tự insert thêm. Giờ mình tìm hiểu qua các nhiều gg mà mình chưa fix được chổ edit này. Mong mọi người help mình với Cảm ơn mọi người
sau đây là đoạn của mình
@GetMapping("/list")
public String List(Model model) {
categoryService.findAll();
model.addAttribute("LIST", categoryService.findAll());
return "view";
}
@GetMapping("/new")
public String show(Model model) {
Category cate = new Category();
model.addAttribute("category", cate);
return "register";
}
@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 void edit( @PathVariable(name="id")Long id, Model model, RedirectAttributes ra,
@RequestParam("fileImage") MultipartFile multipartFile)
{
//hàm edit này mình fix mãi mà ko được
}
Bình luận

{{ comment.user.name }}
Bỏ hay
Hay

Bài viết liên quan

0
5
fCC: Technical Documentation Page note So I have finished the HTML part of this exercise and I want to come here to lament about the lengthy HTML ...

4
0
I used Spring boot, Hibernate few times back then at University, I'v started using it again recently. In this (Link), I want to check how Spring J...

24
1
Toán tử XOR có tính chất: + A XOR A = 0 + 0 XOR A = A Với tính chất này, có thể cài đặt bài toán sau với độ phức tạp O(N) về runtime, và với O(1)...