@RequestMapping(value = "/addStudent", method = RequestMethod.POST)
public String addStudent(@ModelAttribute("SpringWeb") @Validated Student student, BindingResult bindingResult,
ModelMap model) {
if(bindingResult.hasErrors())
{
return new ModelAndView("numberformat", null);
}
model.addAttribute("name", student.getName());
model.addAttribute("age", student.getAge());
model.addAttribute("id", student.getId());
studentService.createStudent(student);
return "redirect:students";
}
The last line will make Spring return an HTTP 302 to the browser which will then perform a GET to the students URL