本文整理汇总了Java中org.springframework.format.datetime.standard.DateTimeFormatterRegistrar类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatterRegistrar类的具体用法?Java DateTimeFormatterRegistrar怎么用?Java DateTimeFormatterRegistrar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeFormatterRegistrar类属于org.springframework.format.datetime.standard包,在下文中一共展示了DateTimeFormatterRegistrar类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDefaultFormatters
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; //导入依赖的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);
}
}
示例2: addDefaultFormatters
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; //导入依赖的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);
}
}
示例3: createFormattingConversionService
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; //导入依赖的package包/类
/**
* Create a FormattingConversionService which use ISO date format, instead of the localized one.
* @return the FormattingConversionService
*/
public static FormattingConversionService createFormattingConversionService() {
DefaultFormattingConversionService dfcs = new DefaultFormattingConversionService ();
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(dfcs);
return dfcs;
}
示例4: localDateFeignFormatterRegistrar
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; //导入依赖的package包/类
/**
* Bugfix for Feign not knowing how to handle @DateTimeFormat in query parameters
*
* see https://github.com/spring-cloud/spring-cloud-netflix/issues/1178
*/
@Bean
public FeignFormatterRegistrar localDateFeignFormatterRegistrar() {
return formatterRegistry -> {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(formatterRegistry);
};
}
示例5: addFormatters
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; //导入依赖的package包/类
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(registry);
}