这不是一个简单的任务。Spring允许进行大量的自定义,但是,该死,这种更改并不有趣。
您需要扩展
RequestMappingHandlerAdapter该类并重写以下方法
protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> binderMethods) throws Exception { return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer());}除了返回
ServletRequestDataBinderFactory,您需要返回一个
InitBinderDataBinderFactory返回自定义
WebDataBinder实例的自定义。
此更改意味着您不能使用默认设置
@EnableWebMvc或
<mvc:annotation-driven/>配置。那是因为它们
RequestMappingHandlerAdapter默认使用,但是您需要注册自己的类。
但是,您可以覆盖带
@Bean注释的
WebMvcConfigurationSupport#requestMappingHandlerAdapter()方法,并提供自己的实现以返回自己的类型。查看该实现对提示的作用。



