Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created October 8, 2016 15:28
Show Gist options
  • Save marti1125/47184c4d212e33075c150b2af1254a0e to your computer and use it in GitHub Desktop.
Save marti1125/47184c4d212e33075c150b2af1254a0e to your computer and use it in GitHub Desktop.
guardar
@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