关于将Web请求绑定到模型对象,我在使用Spring的DataBinder和ConversionService的使用和目的时遇到了一些困惑.出现这种情况是因为我最近尝试通过添加来使用JSR-303验证.
在此之前我用过:
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="mypackage.GlobalWebBindingInitializer" />
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
这很好,因为我想要一个可供多个控制器使用的全局DataBinder.在GlobalWebBindingInitialzer类中实现以下几个:
binder.registerCustomEditor(MyClass.class, new PropertyEditorSupport(MyClass.class)
Run Code Online (Sandbox Code Playgroud)
但是我想使用@Valid注释并添加.这样做的副作用是上面的AnnotationMethodHandlerAdapter bean已经被定义为注释驱动的一部分,因此忽略了我的全局数据绑定器.
所以现在我创建了这个类:
public class MyClassConverter implements Converter<String, MyClass>
Run Code Online (Sandbox Code Playgroud)
我很迷惑.如果我想使用我应该使用转换服务而不是数据仓?