本文整理匯總了Java中org.springframework.format.FormatterRegistry類的典型用法代碼示例。如果您正苦於以下問題:Java FormatterRegistry類的具體用法?Java FormatterRegistry怎麽用?Java FormatterRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FormatterRegistry類屬於org.springframework.format包,在下文中一共展示了FormatterRegistry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void registerFormatters(FormatterRegistry registry) {
DateTimeConverters.registerConverters(registry);
DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);
registry.addFormatterForFieldType(LocalDate.class,
new TemporalAccessorPrinter(dateFormatter),
new TemporalAccessorParser(LocalDate.class, dateFormatter));
registry.addFormatterForFieldType(LocalTime.class,
new TemporalAccessorPrinter(timeFormatter),
new TemporalAccessorParser(LocalTime.class, timeFormatter));
registry.addFormatterForFieldType(LocalDateTime.class,
new TemporalAccessorPrinter(dateTimeFormatter),
new TemporalAccessorParser(LocalDateTime.class, dateTimeFormatter));
registry.addFormatterForFieldType(ZonedDateTime.class,
new TemporalAccessorPrinter(dateTimeFormatter),
new TemporalAccessorParser(ZonedDateTime.class, dateTimeFormatter));
registry.addFormatterForFieldType(OffsetDateTime.class,
new TemporalAccessorPrinter(dateTimeFormatter),
new TemporalAccessorParser(OffsetDateTime.class, dateTimeFormatter));
registry.addFormatterForFieldType(OffsetTime.class,
new TemporalAccessorPrinter(timeFormatter),
new TemporalAccessorParser(OffsetTime.class, timeFormatter));
registry.addFormatterForFieldType(Instant.class, new InstantFormatter());
registry.addFormatterForFieldAnnotation(new Jsr310DateTimeFormatAnnotationFormatterFactory());
}
示例2: addDefaultFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
/**
* Add formatters appropriate for most environments, including number formatters and a Joda-Time
* date formatter if Joda-Time is present on the classpath.
* @param formatterRegistry the service to register default formatters against
*/
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
if (jsr310Present) {
// just handling JSR-310 specific date and time types
new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);
}
if (jodaTimePresent) {
// handles Joda-specific types as well as Date, Calendar, Long
new JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
}
else {
// regular DateFormat-based Date, Calendar, Long converters
new DateFormatterRegistrar().registerFormatters(formatterRegistry);
}
}
示例3: addDefaultFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
/**
* Add formatters appropriate for most environments: including number formatters,
* JSR-354 Money & Currency formatters, JSR-310 Date-Time and/or Joda-Time formatters,
* depending on the presence of the corresponding API on the classpath.
* @param formatterRegistry the service to register default formatters with
*/
public static void addDefaultFormatters(FormatterRegistry formatterRegistry) {
// Default handling of number values
formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
// Default handling of monetary values
if (jsr354Present) {
formatterRegistry.addFormatter(new CurrencyUnitFormatter());
formatterRegistry.addFormatter(new MonetaryAmountFormatter());
formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
}
// Default handling of date-time values
if (jsr310Present) {
// just handling JSR-310 specific date and time types
new DateTimeFormatterRegistrar().registerFormatters(formatterRegistry);
}
if (jodaTimePresent) {
// handles Joda-specific types as well as Date, Calendar, Long
new JodaTimeFormatterRegistrar().registerFormatters(formatterRegistry);
}
else {
// regular DateFormat-based Date, Calendar, Long converters
new DateFormatterRegistrar().registerFormatters(formatterRegistry);
}
}
示例4: registerFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void registerFormatters(FormatterRegistry registry) {
super.registerFormatters(registry);
DateTimeFormatter jodaDateFormatter = getJodaDateFormatter();
if (jodaDateFormatter != null) {
register(registry, LocalDate.class, jodaDateFormatter);
}
DateTimeFormatter jodaTimeFormatter = getJodaTimeFormatter();
if (jodaTimeFormatter != null) {
register(registry, LocalTime.class, jodaTimeFormatter);
}
DateTimeFormatter jodaDateTimeFormatter = getJodaDateTimeFormatter();
if (jodaDateTimeFormatter != null) {
register(registry, DateTime.class, jodaDateTimeFormatter);
}
}
開發者ID:BandwidthOnDemand,項目名稱:bandwidth-on-demand,代碼行數:20,代碼來源:JodaTimeFormattingPatternConfigurer.java
示例5: registerFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void registerFormatters(FormatterRegistry registry) {
JodaTimeConverters.registerConverters(registry);
DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);
addFormatterForFields(registry,
new ReadablePartialPrinter(dateFormatter),
new LocalDateParser(dateFormatter),
LocalDate.class);
addFormatterForFields(registry,
new ReadablePartialPrinter(timeFormatter),
new LocalTimeParser(timeFormatter),
LocalTime.class);
addFormatterForFields(registry,
new ReadablePartialPrinter(dateTimeFormatter),
new LocalDateTimeParser(dateTimeFormatter),
LocalDateTime.class);
addFormatterForFields(registry,
new ReadableInstantPrinter(dateTimeFormatter),
new DateTimeParser(dateTimeFormatter),
ReadableInstant.class);
// In order to retain backwards compatibility we only register Date/Calendar
// types when a user defined formatter is specified (see SPR-10105)
if (this.formatters.containsKey(Type.DATE_TIME)) {
addFormatterForFields(registry,
new ReadableInstantPrinter(dateTimeFormatter),
new DateTimeParser(dateTimeFormatter),
Date.class, Calendar.class);
}
registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
示例6: addFormatterForFields
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
private void addFormatterForFields(FormatterRegistry registry, Printer<?> printer,
Parser<?> parser, Class<?>... fieldTypes) {
for (Class<?> fieldType : fieldTypes) {
registry.addFormatterForFieldType(fieldType, printer, parser);
}
}
示例7: registerFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void registerFormatters(FormatterRegistry registry) {
addDateConverters(registry);
registry.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory());
// In order to retain back compatibility we only register Date/Calendar
// types when a user defined formatter is specified (see SPR-10105)
if (this.dateFormatter != null) {
registry.addFormatter(this.dateFormatter);
registry.addFormatterForFieldType(Calendar.class, this.dateFormatter);
}
}
示例8: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
LongDateTimeFormatAnnotationFormatterFactory longDateFactory =
new LongDateTimeFormatAnnotationFormatterFactory();
registry.addFormatterForFieldAnnotation(longDateFactory);
super.addFormatters(registry);
}
示例9: registerFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void registerFormatters(FormatterRegistry registry) {
DateTimeConverters.registerConverters(registry);
DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);
registry.addFormatterForFieldType(LocalDate.class,
new TemporalAccessorPrinter(dateFormatter),
new TemporalAccessorParser(LocalDate.class, dateFormatter));
registry.addFormatterForFieldType(LocalTime.class,
new TemporalAccessorPrinter(timeFormatter),
new TemporalAccessorParser(LocalTime.class, timeFormatter));
registry.addFormatterForFieldType(LocalDateTime.class,
new TemporalAccessorPrinter(dateTimeFormatter),
new TemporalAccessorParser(LocalDateTime.class, dateTimeFormatter));
registry.addFormatterForFieldType(ZonedDateTime.class,
new TemporalAccessorPrinter(dateTimeFormatter),
new TemporalAccessorParser(ZonedDateTime.class, dateTimeFormatter));
registry.addFormatterForFieldType(OffsetDateTime.class,
new TemporalAccessorPrinter(dateTimeFormatter),
new TemporalAccessorParser(OffsetDateTime.class, dateTimeFormatter));
registry.addFormatterForFieldType(OffsetTime.class,
new TemporalAccessorPrinter(timeFormatter),
new TemporalAccessorParser(OffsetTime.class, timeFormatter));
registry.addFormatterForFieldType(Instant.class, new InstantFormatter());
registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
registry.addFormatterForFieldAnnotation(new Jsr310DateTimeFormatAnnotationFormatterFactory());
}
示例10: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new Converter<TestBean, String>() {
@Override
public String convert(TestBean source) {
return "converted";
}
});
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:10,代碼來源:WebMvcConfigurationSupportExtensionTests.java
示例11: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
if (!(registry instanceof FormattingConversionService)) {
log.warn("Unable to register Spring Data Jpa converter");
return;
}
DomainClassConverter<FormattingConversionService> converter = new DomainClassConverter<FormattingConversionService>(
(FormattingConversionService) registry);
converter.setApplicationContext(this.context);
}
示例12: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addFormatter(DistanceFormatter.INSTANCE);
registry.addFormatter(PointFormatter.INSTANCE);
if (!(registry instanceof FormattingConversionService)) {
return;
}
FormattingConversionService conversionService = (FormattingConversionService) registry;
DomainClassConverter<FormattingConversionService> converter = new DomainClassConverter<FormattingConversionService>(conversionService);
converter.setApplicationContext(context);
}
示例13: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
super.addFormatters(registry);
EntityFormatAnnotationFormatterFactory factory = new EntityFormatAnnotationFormatterFactory(
messageSource, applicationContext, (FormattingConversionService) registry);
registry.addFormatterForFieldAnnotation(factory);
registry.addConverter(factory.getToStringConverter());
registry.addConverter(new EnumToMessageConverter(messageSource));
}
示例14: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
/**
* 注冊Formatter,可以在controller中直接使用@RequestHeader("Range") PageAble Range
* 直接從header中獲取字符串並自動轉換為相應的對象
*/
@Override
public void addFormatters(FormatterRegistry registry) {
if (formatterRegistry != null) {
formatterRegistry.registry(registry);
}
}
示例15: addFormatters
import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
registry.removeConvertible(String.class, Enum.class);
registry.addConverterFactory(new IntStringValueToEnumConverterFactory());
registry.addConverterFactory(new IntegerToEnumConverterFactory());
}