如何在Spring-MVC中注册全球定制编辑器? [英] How can i register a global custom editor in Spring-MVC?
本文介绍了如何在Spring-MVC中注册全球定制编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MANY Spring-MVC控制器中使用以下自定义编辑器:
I use the following custom editor in MANY Spring-MVC controllers according to:
控制器
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
其他控制器
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
另一个控制器
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
注意注册相同的自定义编辑器
Notice the same custom editor registered
问题:我如何设置像这样的全局自定义编辑器,以避免设置每个控制器?
Question: how can i set up a global custom editor like this one in order to avoid set up each controller ?
regards,
解决方案
你需要在你的应用程序上下文中声明:
You need to declare it in your application context:
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors"><map>
<entry key="java.math.BigDecimal">
<bean class="org.springframework.beans.propertyeditors.CustomNumberEditor">
... <!-- specify constructor-args here -->
</bean>
</entry>
</map></property>
</bean>
详细信息是 here
这篇关于如何在Spring-MVC中注册全球定制编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文