From 8e3a4148470351394b5bfc8aa5f093af9743064a Mon Sep 17 00:00:00 2001 From: aleyckin Date: Thu, 25 May 2023 17:14:20 +0400 Subject: [PATCH] =?UTF-8?q?5=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=B0=D1=81=D1=8C=20=D0=B4=D0=BE=D0=BF=D0=BA?= =?UTF-8?q?=D0=B0(=D0=BD=D0=B0=D0=B2=D0=B5=D1=80=D0=BD=D0=BE=D0=B5)=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D1=80=20=D0=B8=D0=B7=204=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../ulstu/is/sbapp/HardwareShop/controller/ProductDTO.java | 2 ++ .../sbapp/HardwareShop/controller/ProductMvcController.java | 5 ++++- src/main/resources/templates/manufacturer-update.html | 2 ++ src/main/resources/templates/product-mtm.html | 2 +- src/main/resources/templates/product-update.html | 4 ++-- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 59873d2..e12cdfb 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { group = 'ru.ulstu.is' version = '0.0.1-SNAPSHOT' -sourceCompatibility = '19' +sourceCompatibility = '17' repositories { mavenCentral() diff --git a/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductDTO.java b/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductDTO.java index 8a49791..85b7bed 100644 --- a/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductDTO.java +++ b/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductDTO.java @@ -59,4 +59,6 @@ public class ProductDTO { public void setPrice(Integer price) { this.price = price; } public void setCategoryName(String name) { this.categoryName = name; } + + public void setCategory_id(Long categoryId) {this.category_id = categoryId;} } diff --git a/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductMvcController.java b/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductMvcController.java index 6c9d4ea..a91d12e 100644 --- a/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductMvcController.java +++ b/src/main/java/ru/ulstu/is/sbapp/HardwareShop/controller/ProductMvcController.java @@ -38,6 +38,7 @@ public class ProductMvcController { @GetMapping(value = {"/update", "/update/{id}"}) public String updateProduct(@PathVariable(required = false) Long id, Model model) { + model.addAttribute("categories",categoryService.findAllCategories()); model.addAttribute("Manufacturers", manufacturerService.findAllManufacturers()); if (id == null || id <= 0) { model.addAttribute("productDto", new ProductDTO()); @@ -51,6 +52,7 @@ public class ProductMvcController { @PostMapping(value = {"/", "/{id}"}) public String saveProduct(@PathVariable(required = false) Long id, @RequestParam(value = "multipartFile") MultipartFile multipartFile, + @RequestParam(value = "categoryId") Long category_id, @ModelAttribute("productDto") ProductDTO productDTO, BindingResult bindingResult, Model model) throws IOException { @@ -60,9 +62,10 @@ public class ProductMvcController { return "product-update"; } productDTO.setPhoto("data:" + multipartFile.getContentType() + ";base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes())); + productDTO.setCategory_id(category_id); productDTO.setCategoryName(categoryService.findCategory(productDTO.getCategory_id()).getName()); if (id == null || id <= 0) { - productService.addProduct(productDTO); + return "redirect:/product/" + productService.addProduct(productDTO).getId().toString() + "/manufacturers"; } else { productService.updateProduct(id, productDTO); } diff --git a/src/main/resources/templates/manufacturer-update.html b/src/main/resources/templates/manufacturer-update.html index ba5890e..5f5bb58 100644 --- a/src/main/resources/templates/manufacturer-update.html +++ b/src/main/resources/templates/manufacturer-update.html @@ -11,6 +11,8 @@
+ +
-
+ diff --git a/src/main/resources/templates/product-update.html b/src/main/resources/templates/product-update.html index 30a5779..93e9b6d 100644 --- a/src/main/resources/templates/product-update.html +++ b/src/main/resources/templates/product-update.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml"> @@ -22,7 +22,7 @@ -