@Bean public FormattingConversionService mvcConserConversionService() { DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(true); DateFormatterRegistrar registrar = new DateFormatterRegistrar(); registrar.setFormatter(new DateFormatter("yyy-MM-dd")); registrar.registerFormatters(conversionService); return conversionService; }
@Bean public FormattingConversionService conversionService() { DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false); conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); DateFormatterRegistrar registrar = new DateFormatterRegistrar(); DateFormatter dateFormatter = new DateFormatter(); dateFormatter.setIso(ISO.DATE); registrar.setFormatter(dateFormatter); registrar.registerFormatters(conversionService); return conversionService; }
/** * Install the converters into the converter registry. * * @param registry the converter registry */ public static void registerConverters(ConverterRegistry registry) { DateFormatterRegistrar.addDateConverters(registry); registry.addConverter(new DateTimeToLocalDateConverter()); registry.addConverter(new DateTimeToLocalTimeConverter()); registry.addConverter(new DateTimeToLocalDateTimeConverter()); registry.addConverter(new DateTimeToDateMidnightConverter()); registry.addConverter(new DateTimeToMutableDateTimeConverter()); registry.addConverter(new DateTimeToInstantConverter()); registry.addConverter(new DateTimeToDateConverter()); registry.addConverter(new DateTimeToCalendarConverter()); registry.addConverter(new DateTimeToLongConverter()); registry.addConverter(new DateToReadableInstantConverter()); registry.addConverter(new CalendarToReadableInstantConverter()); }