use redirect to void duplicate submission

《Spring in Action3》笔记:

@RequestMapping(method=RequestMethod.POST)
public StringaddSpitterFromForm(@Valid Spitter spitter, BindingResult bindingResult){
  if(bindingResult.hasErrors()){
       return"spitters/edit";
  }
  spitterService.saveSpitter(spitter);
  return "redirect:/spitters/"+spitter.getUsername();
}
 

By redirecting to another page, we can avoid duplicate submission of the form if the user
clicks the Refresh button in their browser.

你可能感兴趣的:(redirect)