从Spring
3.0开始,您可以设置
ConversionService。
@InitBinder的
value指定了一个特定的参数来将该服务应用于:
@InitBinder("page")public void initBinder(WebDataBinder binder) { FormattingConversionService s = new FormattingConversionService(); s.addFormatterForFieldType(Integer.class, new Formatter<Integer>() { public String print(Integer value, Locale locale) { return value.toString(); } public Integer parse(String value, Locale locale) throws ParseException { try { return Integer.valueOf(value); } catch (NumberFormatException ex) { return 1; } } }); binder.setConversionService(s);}


