user3198603
user3198603

Reputation: 5816

What does InitBinder actually mean here?

Spring docs says this about InitBinder

Annotation that identifies methods which initialize the WebDataBinder which will be used for populating command and form object arguments of annotated handler methods.

What i got from this this method is used for initializing the WebDataBinder which is used to populate model object so that it can be used further in handler method. But i am not sure what does "... of annotated handler methods" mean here?"

Update :- i believe it means after going thru Sotirios Delimanolis answer

InitBinder Annotation identifies methods which initialize the WebDataBinder which will be used for model object that is further passes to handler method annotated with @RequestMapping

Upvotes: 0

Views: 799

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279960

A handler method is typically meant to distinguish methods annotated with @RequestMapping within a @Controller or @RequestMapping annotated type (see RequestMappingHandlerMapping).

For example,

@RequestMapping("/example")
public String setItemValue(@ModelAttribute Item item) {
    item.setValue(42);
    return "some-view";
}

An @InitBinder method could be used to help populate the WebDataBinder which will create the argument to be passed to the setItemValue handler method.

Here's some extra reading on @ModelAttribute. It is not necessarily required (just being explicit).

Upvotes: 1

Related Questions