From c6889698bf40ca4e4909b1cda76f696a553777ef Mon Sep 17 00:00:00 2001 From: Ino Date: Fri, 28 Apr 2023 16:51:14 +0400 Subject: [PATCH] de --- .../supply/Supplier/ProductMvcController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 demo/src/main/java/com/example/demo/supply/Supplier/ProductMvcController.java diff --git a/demo/src/main/java/com/example/demo/supply/Supplier/ProductMvcController.java b/demo/src/main/java/com/example/demo/supply/Supplier/ProductMvcController.java new file mode 100644 index 0000000..28f352b --- /dev/null +++ b/demo/src/main/java/com/example/demo/supply/Supplier/ProductMvcController.java @@ -0,0 +1,26 @@ +package com.example.demo.supply.Supplier; + +import com.example.demo.supply.Product.ProductDto; +import com.example.demo.supply.Product.ProductService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.List; + +@Controller +@RequestMapping("/product") +public class ProductMvcController { + private final ProductService productService; + + public ProductMvcController(ProductService productService){ this.productService = productService;} + + @GetMapping("/") + public String getProducts(Model model) { + model.addAttribute("students", + productService.findAllProducts().stream().map(ProductDto::new).toList()); + return "students"; + } + +}