上QQ阅读APP看书,第一时间看更新
How it works...
Spring automatically configures a large number of default editors; but for custom types, we have to explicitly instantiate new editors for every web request. This is done in the controller in a method that is annotated with @InitBinder. This annotation is scanned and all the detected methods should have a signature of accepting WebDataBinder as an argument. Among other things, WebDataBinder provides us with an ability to register as many custom editors as we require for the controller methods to be bound properly.
It is very important to know that PropertyEditor is not thread-safe! For this reason, we have to create a new instance of our custom editors for every web request and register them with WebDataBinder.
In case a new PropertyEditor is needed, it is best to create one by extending PropertyEditorSupport and overriding the desired methods with custom implementation.