如何在 Spring-MVC 中注册全局自定义编辑器? [英] How can i register a global custom editor in Spring-MVC?
本文介绍了如何在 Spring-MVC 中注册全局自定义编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在许多 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 ?
问候,
推荐答案
你需要在你的应用程序上下文中声明它:
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>
详情这里
这篇关于如何在 Spring-MVC 中注册全局自定义编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文