Created
September 4, 2019 18:53
-
-
Save parzibyte/574b255d98fec2bf386718e905bd2797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PostMapping(value = "/agregar") | |
public String guardarProducto(@ModelAttribute @Valid Producto producto, BindingResult bindingResult, RedirectAttributes redirectAttrs) { | |
if (bindingResult.hasErrors()) { | |
return "productos/agregar_producto"; | |
} | |
if (productosRepository.findFirstByCodigo(producto.getCodigo()) != null) { | |
redirectAttrs | |
.addFlashAttribute("mensaje", "Ya existe un producto con ese código") | |
.addFlashAttribute("clase", "warning"); | |
return "redirect:/productos/agregar"; | |
} | |
productosRepository.save(producto); | |
redirectAttrs | |
.addFlashAttribute("mensaje", "Agregado correctamente") | |
.addFlashAttribute("clase", "success"); | |
return "redirect:/productos/agregar"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment