org.springframework.core.convert.Property#org.springframework.format.annotation.NumberFormat源码实例Demo

下面列出了org.springframework.core.convert.Property#org.springframework.format.annotation.NumberFormat 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
	String pattern = resolveEmbeddedValue(annotation.pattern());
	if (StringUtils.hasLength(pattern)) {
		return new NumberStyleFormatter(pattern);
	}
	else {
		Style style = annotation.style();
		if (style == Style.CURRENCY) {
			return new CurrencyStyleFormatter();
		}
		else if (style == Style.PERCENT) {
			return new PercentStyleFormatter();
		}
		else {
			return new NumberStyleFormatter();
		}
	}
}
 
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) {
	String pattern = resolveEmbeddedValue(annotation.pattern());
	if (StringUtils.hasLength(pattern)) {
		return new PatternDecoratingFormatter(pattern);
	}
	else {
		Style style = annotation.style();
		if (style == Style.NUMBER) {
			return new NumberDecoratingFormatter(new NumberStyleFormatter());
		}
		else if (style == Style.PERCENT) {
			return new NumberDecoratingFormatter(new PercentStyleFormatter());
		}
		else {
			return new NumberDecoratingFormatter(new CurrencyStyleFormatter());
		}
	}
}
 
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
	String pattern = resolveEmbeddedValue(annotation.pattern());
	if (StringUtils.hasLength(pattern)) {
		return new NumberStyleFormatter(pattern);
	}
	else {
		Style style = annotation.style();
		if (style == Style.CURRENCY) {
			return new CurrencyStyleFormatter();
		}
		else if (style == Style.PERCENT) {
			return new PercentStyleFormatter();
		}
		else {
			return new NumberStyleFormatter();
		}
	}
}
 
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) {
	String pattern = resolveEmbeddedValue(annotation.pattern());
	if (StringUtils.hasLength(pattern)) {
		return new PatternDecoratingFormatter(pattern);
	}
	else {
		Style style = annotation.style();
		if (style == Style.NUMBER) {
			return new NumberDecoratingFormatter(new NumberStyleFormatter());
		}
		else if (style == Style.PERCENT) {
			return new NumberDecoratingFormatter(new PercentStyleFormatter());
		}
		else {
			return new NumberDecoratingFormatter(new CurrencyStyleFormatter());
		}
	}
}
 
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
	if (StringUtils.hasLength(annotation.pattern())) {
		return new NumberStyleFormatter(resolveEmbeddedValue(annotation.pattern()));
	}
	else {
		Style style = annotation.style();
		if (style == Style.CURRENCY) {
			return new CurrencyStyleFormatter();
		}
		else if (style == Style.PERCENT) {
			return new PercentStyleFormatter();
		}
		else {
			return new NumberStyleFormatter();
		}
	}
}
 
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) {
	if (StringUtils.hasLength(annotation.pattern())) {
		return new PatternDecoratingFormatter(resolveEmbeddedValue(annotation.pattern()));
	}
	else {
		Style style = annotation.style();
		if (style == Style.NUMBER) {
			return new NumberDecoratingFormatter(new NumberStyleFormatter());
		}
		else if (style == Style.PERCENT) {
			return new NumberDecoratingFormatter(new PercentStyleFormatter());
		}
		else {
			return new NumberDecoratingFormatter(new CurrencyStyleFormatter());
		}
	}
}
 
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
	if (StringUtils.hasLength(annotation.pattern())) {
		return new NumberStyleFormatter(resolveEmbeddedValue(annotation.pattern()));
	}
	else {
		Style style = annotation.style();
		if (style == Style.CURRENCY) {
			return new CurrencyStyleFormatter();
		}
		else if (style == Style.PERCENT) {
			return new PercentStyleFormatter();
		}
		else {
			return new NumberStyleFormatter();
		}
	}
}
 
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) {
	if (StringUtils.hasLength(annotation.pattern())) {
		return new PatternDecoratingFormatter(resolveEmbeddedValue(annotation.pattern()));
	}
	else {
		Style style = annotation.style();
		if (style == Style.NUMBER) {
			return new NumberDecoratingFormatter(new NumberStyleFormatter());
		}
		else if (style == Style.PERCENT) {
			return new NumberDecoratingFormatter(new PercentStyleFormatter());
		}
		else {
			return new NumberDecoratingFormatter(new CurrencyStyleFormatter());
		}
	}
}
 
源代码9 项目: jdal   文件: FormatUtils.java
/**
 * Get a formatter for class and property name
 * @param clazz the class
 * @param propertyName the property name
 * @return the formatter or null if none
 */
public static Formatter<?> getFormatter(Class<?> clazz, String propertyName) {
	PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(clazz, propertyName);
	if (pd != null) {
		NumberFormat format = getAnnotation(pd, NumberFormat.class);
		if (format != null) {
			return (Formatter<?>) numberFormatFactory.getPrinter(format, pd.getPropertyType());
		}
		
		PeriodFormat periodFormat = getAnnotation(pd, PeriodFormat.class);
		if (periodFormat != null)
			return new PeriodFormatter();
	}
	
	return null;
}
 
@Override
public Printer<Number> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
源代码14 项目: spring-analysis-note   文件: EvalTagTests.java
@NumberFormat(style=Style.PERCENT)
public BigDecimal getFormattable() {
	return new BigDecimal(".25");
}
 
@Override
public Printer<Number> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
源代码19 项目: java-technology-stack   文件: EvalTagTests.java
@NumberFormat(style=Style.PERCENT)
public BigDecimal getFormattable() {
	return new BigDecimal(".25");
}
 
@RequestMapping(method = RequestMethod.GET)
String getTest(@RequestParam("amount") @NumberFormat(
		pattern = CUSTOM_PATTERN) BigDecimal amount);
 
@Override
public Printer<Number> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Printer<Number> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
@Override
public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
源代码29 项目: spring4-understanding   文件: EvalTagTests.java
@NumberFormat(style=Style.PERCENT)
public BigDecimal getFormattable() {
	return new BigDecimal(".25");
}