Spring 3 Controller中的自定义数据绑定器

时间:2013-04-03 10:54:59

标签: spring spring-mvc controller spring-3

在控制器中注册自定义数据绑定器的弹簧2方法是覆盖扩展弹簧控制器的createBinder方法。春天3的方式是什么?我们使用@Controller注释,因此没有我可以覆盖的钩子。我本以期待像“@CreateBinder”这样的东西。

搜索网络不是很有帮助。我只发现了this相关主题。

要明确这一点:这不是关于设置属性编辑器。我可以使用@InitBinding。

1 个答案:

答案 0 :(得分:1)

使用@InitBinder注释。

@InitBinder
public void initBinderAll(WebDataBinder binder) {
    binder.registerCustomEditor(Country.class,  new CountryEditor());
}

西蒙