當前位置: 首頁>>代碼示例>>Java>>正文


Java FormatterRegistry類代碼示例

本文整理匯總了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());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:37,代碼來源:DateTimeFormatterRegistrar.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:DefaultFormattingConversionService.java

示例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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:32,代碼來源:DefaultFormattingConversionService.java

示例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());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:JodaTimeFormatterRegistrar.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:JodaTimeFormatterRegistrar.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:DateFormatterRegistrar.java

示例8: addFormatters

import org.springframework.format.FormatterRegistry; //導入依賴的package包/類
@Override
public void addFormatters(FormatterRegistry registry) {
    LongDateTimeFormatAnnotationFormatterFactory longDateFactory =
            new LongDateTimeFormatAnnotationFormatterFactory();
    registry.addFormatterForFieldAnnotation(longDateFactory);
    super.addFormatters(registry);
}
 
開發者ID:pandboy,項目名稱:pingguopai,代碼行數:8,代碼來源:WebMvcConfigurer.java

示例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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:41,代碼來源:DateTimeFormatterRegistrar.java

示例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);
}
 
開發者ID:shilongdai,項目名稱:bookManager,代碼行數:12,代碼來源:ServletApplicationContextConfig.java

示例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);
}
 
開發者ID:xiangxik,項目名稱:java-platform,代碼行數:15,代碼來源:WebConfiguration.java

示例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));
}
 
開發者ID:DISID,項目名稱:springlets,代碼行數:11,代碼來源:SpringletsEntityFormatWebConfiguration.java

示例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);
    }
}
 
開發者ID:ismartx,項目名稱:summer,代碼行數:11,代碼來源:WebConfig.java

示例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());
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:9,代碼來源:BootMvcConfigurerAdapter.java


注:本文中的org.springframework.format.FormatterRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。