Commit f0517907 by Patryk Czarnik

Zapis danych z formularza - oddzielne parametry

parent ebdc118a
...@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller; ...@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -89,6 +90,24 @@ public class ProductController { ...@@ -89,6 +90,24 @@ public class ProductController {
// W tej metodzie wyświetlamy pusty formularz // W tej metodzie wyświetlamy pusty formularz
return "product_form"; return "product_form";
} }
@PostMapping({"/{id}/edit", "/new"})
// Ta metoda zapisuje dane przysłane z formularza obojętnie, czy to było edit, czy new
public String saveProduct(Integer productId, String productName, BigDecimal price, BigDecimal vat, String description,
Model model) {
Product product = new Product();
product.setProductId(productId);
product.setProductName(productName);
product.setPrice(price);
product.setVat(vat);
product.setDescription(description);
System.out.println("id przed zapisem: " + product.getProductId());
productRepository.save(product);
System.out.println("id po zapisie: " + product.getProductId());
model.addAttribute("product", product);
return "product_form";
}
@GetMapping(path="/{id}/photo", produces="image/jpeg") @GetMapping(path="/{id}/photo", produces="image/jpeg")
@ResponseBody @ResponseBody
......
...@@ -10,7 +10,9 @@ public class SecurityConfig { ...@@ -10,7 +10,9 @@ public class SecurityConfig {
@Bean @Bean
SecurityFilterChain configHttpSecurity(HttpSecurity httpSecurity) throws Exception { SecurityFilterChain configHttpSecurity(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeHttpRequests(authz -> authz.anyRequest().permitAll()); httpSecurity
.authorizeHttpRequests(authz -> authz.anyRequest().permitAll())
.csrf(authz -> authz.disable());
return httpSecurity.build(); return httpSecurity.build();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment