我正在开发一个Spring 3项目,我需要Long
为土耳其货币格式化一个字段.Locale
应用程序的默认值是en_US
.我使用了@NumberFormat
如下注释:
@NumberFormat(style=NumberFormat.Style.CURRENCY) public Long getBudgetLimit() { return budgetLimit; }
注释用于处理英语区域设置中的表单字段.但是,我需要在此字段中使用土耳其语区域设置.有没有办法设置单个字段或不同于应用程序区域设置的页面的区域设置?
编辑:我刚刚找到了答案.在控制器中使用自定义编辑器,如下所示:
NumberFormat numberFormat = NumberFormat.getNumberInstance(new Locale("tr","TR")); dataBinder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class,numberFormat, true));
并且不要使用@NumberFormat
注释.出于同样的原因,它给了我一个错误.