• +91 9723535972
  • info@interviewmaterial.com

Spring Interview Questions and Answers

Question - Why do we need BindingResults?

Answer -

BindingResults is an important Spring interface that is within the org.Springframework.validation package. This interface has a very simple and easy process of invocation and plays a vital role in detecting errors in the submitted forms. However, care has to be taken by the developer to use the BindingResult parameter just after the object that needs validation. For example:

@PostMapping("/interviewbit")
public String registerCourse(@Valid RegisterUser registerUser,
 BindingResult bindingResult, Model model) {
   if (bindingResult.hasErrors()) {
       return "home";
   }
   model.addAttribute("message", "Valid inputs");
   return "home";
}
The Spring will understand to find the corresponding validators by checking the @Valid annotation on the parameter.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners