首页>代码>spring mvc-showcase,便于学习springmvc,maven工程,建议使用谷歌浏览器>/spring-mvc-showcase/src/main/java/org/springframework/samples/mvc/convert/MaskFormatAnnotationFormatterFactory.java
package org.springframework.samples.mvc.convert; import java.text.ParseException; import java.util.HashSet; import java.util.Locale; import java.util.Set; import org.springframework.format.AnnotationFormatterFactory; import org.springframework.format.Formatter; import org.springframework.format.Parser; import org.springframework.format.Printer; public class MaskFormatAnnotationFormatterFactory implements AnnotationFormatterFactory<MaskFormat> { public Set<Class<?>> getFieldTypes() { Set<Class<?>> fieldTypes = new HashSet<Class<?>>(1, 1); fieldTypes.add(String.class); return fieldTypes; } public Parser<?> getParser(MaskFormat annotation, Class<?> fieldType) { return new MaskFormatter(annotation.value()); } public Printer<?> getPrinter(MaskFormat annotation, Class<?> fieldType) { return new MaskFormatter(annotation.value()); } private static class MaskFormatter implements Formatter<String> { private javax.swing.text.MaskFormatter delegate; public MaskFormatter(String mask) { try { this.delegate = new javax.swing.text.MaskFormatter(mask); this.delegate.setValueContainsLiteralCharacters(false); } catch (ParseException e) { throw new IllegalStateException("Mask could not be parsed " + mask, e); } } public String print(String object, Locale locale) { try { return delegate.valueToString(object); } catch (ParseException e) { throw new IllegalArgumentException("Unable to print using mask " + delegate.getMask(), e); } } public String parse(String text, Locale locale) throws ParseException { return (String) delegate.stringToValue(text); } } }
最近下载更多
lwp011 LV27
2020年7月7日
truenoakina123 LV3
2019年10月17日
其他昵称 LV10
2018年8月31日
chinafjfzlj LV31
2017年9月7日
shifukuan LV10
2017年9月1日
sevenvsky LV27
2016年12月29日
huangguoqiang LV1
2016年8月19日
huachen LV2
2016年5月29日
luoshaoke LV1
2016年4月14日
jefferyqjy LV1
2015年12月13日
最近浏览更多
a1677596408 LV23
2022年7月1日
twedss
2022年6月17日
暂无贡献等级
anbangchen89 LV2
2022年3月3日
535871265
2022年1月10日
暂无贡献等级
HCY666 LV2
2021年12月22日
1727779658 LV7
2021年12月20日
Hadoop_CPU LV6
2021年11月29日
fengzhou888 LV5
2021年11月26日
2532467971 LV2
2021年10月14日
王东东 LV17
2021年3月21日