@RequestMapping(value="/add", method = RequestMethod.GET)
public String add(Model uiModel) {
if (!uiModel.containsAttribute("toAdd")) {
uiModel.addAttribute("toAdd",new ToAdd());
}
}
@RequestMapping(value="/add", method = RequestMethod.POST)
public String add(@Valid ToAdd toAdd,
BindingResult bindingResult,
RedirectAttributes redirectAttributes) {
if (serial == null) throw new ResourceNotFoundException();
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.toAdd", bindingResult);
redirectAttributes.addFlashAttribute("toAdd",toAdd);
}
else {
toAdd.persist(); //Or whatever you want to do here
}
return "redirect:/add";
}