Command (Form Backing) Objects:-
Spring uses the notion of a command object, which essentially is a JavaBean style class that gets populated with the data from an HTML form’s fields.This same object is also passed to our validators for data validation, and if the validations pass, it is passed to the onSubmit method (in controller related classes) for processing of valid data. Given that this command object is a simple JavaBean-style class, we can use our business objects directly for data binding instead of writing special classes just for data binding.
(OR)
Command Objects are POJOs used to bind the request data and make it available on screen. In Struts action forms, we used to extend the objects from a Struts class, but here we don’t need to do it. This is one of the advantages of Spring, that the data objects are not coupled with the framework. There is difference between the command object and form when these terms are used in Spring MVC documentation.The term ‘Form’ is used to describe the process of binding attributes of the object with fields of a screen form. Thus, submission, resubmission etc. features are associated with respect to a form.
@RequestMapping("/somepath/foo/do")
public String someHandlerMethod(
@ModelAttribute("commandObject") CommandObject commandObject,
Model model,
BindingResult result) {
...processing...
return("");
}