本文整理汇总了Java中org.springframework.format.annotation.NumberFormat类的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat类的具体用法?Java NumberFormat怎么用?Java NumberFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NumberFormat类属于org.springframework.format.annotation包,在下文中一共展示了NumberFormat类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureFormatterFrom
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) {
if (StringUtils.hasLength(annotation.pattern())) {
return new NumberFormatter(resolveEmbeddedValue(annotation.pattern()));
}
else {
Style style = annotation.style();
if (style == Style.PERCENT) {
return new PercentFormatter();
}
else if (style == Style.CURRENCY) {
return new CurrencyFormatter();
}
else {
return new NumberFormatter();
}
}
}
示例2: configureFormatterFrom
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
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();
}
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:NumberFormatAnnotationFormatterFactory.java
示例3: configureFormatterFrom
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
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());
}
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java
示例4: toFlatMap
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
public static Map<String, Object> toFlatMap(Object obj, Function<Object, Boolean> isNestedObject) {
Map<String, Object> map = Maps.newHashMap();
BEAN_TO_MAP_CONVERTOR.flatObject("", obj, (k, v, ctx)->{
Object value = v;
TypeDescriptor sourceType = null;
if(v.getClass()!=String.class){
Field field = ctx.getField();
if(field!=null && (field.getAnnotation(DateTimeFormat.class)!=null || field.getAnnotation(NumberFormat.class)!=null) ){
sourceType = new TypeDescriptor(field);
}
if(sourceType==null){
sourceType = new TypeDescriptor(new Property(ctx.getSource().getClass(), ctx.getProperty().getReadMethod(), ctx.getProperty().getWriteMethod()));
}
value = getFormattingConversionService().convert(v, sourceType, TypeDescriptor.valueOf(String.class));
}
map.put(k, value);
});
return map;
}
示例5: getFormatter
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
/**
* 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;
}
示例6: getPrinter
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
@Override
public Printer<Number> getPrinter(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}
示例7: getParser
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}
示例8: getPrinter
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
@Override
public Printer<MonetaryAmount> getPrinter(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java
示例9: getParser
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
@Override
public Parser<MonetaryAmount> getParser(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:Jsr354NumberFormatAnnotationFormatterFactory.java
示例10: getFormattable
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
@NumberFormat(style=Style.PERCENT)
public BigDecimal getFormattable() {
return new BigDecimal(".25");
}
示例11: createAttribute
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
private Attribute createAttribute(String parent, Field field, boolean id, boolean editable, boolean listable){
String renderingType = null;
Object renderingObject = null;
if(field.getType().isEnum()){
renderingType = "radio";
String contents = "T("+field.getType().getName()+").values()";
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(contents);
renderingObject = exp.getValue();
}else if(ClassUtils.isAssignable(MultipartFile.class, field.getType())){
renderingType = "file";
}else if(ClassUtils.isAssignable(Number.class, field.getType())){
renderingType = "number";
}else if(
ClassUtils.isAssignable(DateTime.class, field.getType()) ||
ClassUtils.isAssignable(java.util.Date.class, field.getType()) ||
ClassUtils.isAssignable(java.sql.Date.class, field.getType()) ||
ClassUtils.isAssignable(java.sql.Time.class, field.getType()) ||
ClassUtils.isAssignable(java.sql.Timestamp.class, field.getType())
){
renderingType = "date";
}else if(field.isAnnotationPresent(DateTimeFormat.class)){
renderingType = "date";
DateTimeFormat dateTimeFormat = field.getAnnotation(DateTimeFormat.class);
renderingObject = dateTimeFormat.pattern();
}else if(field.isAnnotationPresent(NumberFormat.class)){
renderingType = "number";
NumberFormat numberFormat = field.getAnnotation(NumberFormat.class);
renderingObject = numberFormat.pattern();
}
String name = StringUtils.hasText(parent) ? parent+"."+field.getName() : field.getName();
Attribute a = new Attribute();
a.setName(name);
a.setId(id);
a.setEditable(editable);
a.setListable(listable);
a.setRenderingType(renderingType);
a.setRenderingObject(renderingObject);
return a;
}
示例12: getPrinter
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
public Printer<Number> getPrinter(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}
示例13: getParser
import org.springframework.format.annotation.NumberFormat; //导入依赖的package包/类
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}