当前位置: 首页>>代码示例>>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;未经允许,请勿转载。