Created
October 8, 2016 15:28
-
-
Save marti1125/47184c4d212e33075c150b2af1254a0e to your computer and use it in GitHub Desktop.
guardar
This file contains hidden or 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
@RequestMapping(value = "/clientes/guardar", method = { RequestMethod.POST }) | |
public String guardarcliente(Model model, @Valid Cliente cliente, BindingResult bindingResult) throws ParseException { | |
model.addAttribute("fechaNacimiendo",new Util().DatetoString(cliente.getFecNacCliente())); | |
if(clienteRepository.findByNroDocumento(cliente.getNroDocumento()) != null){ | |
ObjectError error = new ObjectError("nroDocumento","Cliente ya se encuentra registrado."); | |
bindingResult.addError(error); | |
} | |
if (bindingResult.hasErrors()) { | |
model.addAttribute("tipoDocumentos", tipoDocumentosRep.findAll()); | |
model.addAttribute("tipoClientes", tipoClienteRep.findAll()); | |
model.addAttribute("generos", generoRep.findAll()); | |
model.addAttribute("sedes", sedeRep.findAll()); | |
model.addAttribute("distritos", distritoRep.findAll()); | |
model.addAttribute("cliente",cliente); | |
return "crearcliente"; | |
} else { | |
clienteRepository.save(cliente); | |
return "redirect:/clientes"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment