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 @@ -