5 лаба осталась допка(наверное) добавить фильтр из 4 лабы

This commit is contained in:
aleyckin 2023-05-25 17:14:20 +04:00
parent 743f35ffef
commit 8e3a414847
6 changed files with 12 additions and 5 deletions

View File

@ -6,7 +6,7 @@ plugins {
group = 'ru.ulstu.is'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '19'
sourceCompatibility = '17'
repositories {
mavenCentral()

View File

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

View File

@ -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);
}

View File

@ -11,6 +11,8 @@
<div class="mb-3">
<label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" th:field="${manufacturerDto.name}" required="true">
<label for="name" class="form-label">Адресс</label>
<input type="text" class="form-control" id="address" th:field="${manufacturerDto.address}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-success button-fixed">

View File

@ -24,7 +24,7 @@
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</div>
<form th:action="@{/product/{id}/manufacturers/{manufacturerid}(id=${product.id}, manufacturerid=${bg.id})}" method="post">
<form th:action="@{/product/{id}/manufacturers/{manufacturerid}(id=${product.id}, manufacturerid=${pm.id})}" method="post">
<button th:id="'remove-' + ${pm.id}" type="submit" style="display: none">
Удалить
</button>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
@ -22,7 +22,7 @@
<img th:src="${productDto.photo}" class="img-thumbnail mw-50 mh-50"/>
</div>
<label for="category" class="form-label">Категория</label>
<select id="category" class="form-control" th:field="${productDto.category_id}">
<select id="category" class="form-control" th:name="categoryId">
<option th:each="category : ${categories}" th:value="${category.id}" th:text="${category.name}"></option>
</select>
<div class="mb-3">