polish
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1799 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
aff628f177
commit
8330c6c88d
|
|
@ -801,9 +801,9 @@ public class StringToInteger implements Converter<String, Integer> {
|
||||||
<programlisting language="java"><![CDATA[
|
<programlisting language="java"><![CDATA[
|
||||||
public interface ConversionService {
|
public interface ConversionService {
|
||||||
|
|
||||||
boolean canConvert(Class<?> sourceType, Class<?> targetType);
|
boolean canConvert(Class<?> sourceType, Class<?> targetType);
|
||||||
|
|
||||||
<T> T convert(Object source, Class<T> targetType);
|
<T> T convert(Object source, Class<T> targetType);
|
||||||
|
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
@ -839,7 +839,7 @@ public interface ConversionService {
|
||||||
<bean id="conversionService" class="org.springframework.core.convert.support.DefaultConversionService">
|
<bean id="conversionService" class="org.springframework.core.convert.support.DefaultConversionService">
|
||||||
<property name="converters">
|
<property name="converters">
|
||||||
<list>
|
<list>
|
||||||
<bean class="example.MyCustomConverter" />
|
<bean class="example.MyCustomConverter" />
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
</bean>]]>
|
</bean>]]>
|
||||||
|
|
@ -921,31 +921,31 @@ package org.springframework.ui.format.date;
|
||||||
|
|
||||||
public final class DateFormatter implements Formatter<Date> {
|
public final class DateFormatter implements Formatter<Date> {
|
||||||
|
|
||||||
private String pattern;
|
private String pattern;
|
||||||
|
|
||||||
public DateFormatter(String pattern) {
|
public DateFormatter(String pattern) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String format(Date date, Locale locale) {
|
public String format(Date date, Locale locale) {
|
||||||
if (date == null) {
|
if (date == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return getDateFormat(locale).format(date);
|
return getDateFormat(locale).format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date parse(String formatted, Locale locale) throws ParseException {
|
public Date parse(String formatted, Locale locale) throws ParseException {
|
||||||
if (formatted.length() == 0) {
|
if (formatted.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return getDateFormat(locale).parse(formatted);
|
return getDateFormat(locale).parse(formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DateFormat getDateFormat(Locale locale) {
|
protected DateFormat getDateFormat(Locale locale) {
|
||||||
DateFormat dateFormat = new SimpleDateFormat(this.pattern, locale);
|
DateFormat dateFormat = new SimpleDateFormat(this.pattern, locale);
|
||||||
dateFormat.setLenient(false);
|
dateFormat.setLenient(false);
|
||||||
return dateFormat;
|
return dateFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
@ -979,7 +979,7 @@ public class Money {
|
||||||
package org.springframework.ui.format;
|
package org.springframework.ui.format;
|
||||||
|
|
||||||
public interface AnnotationFormatterFactory<A extends Annotation, T> {
|
public interface AnnotationFormatterFactory<A extends Annotation, T> {
|
||||||
Formatter<T> getFormatter(A annotation);
|
Formatter<T> getFormatter(A annotation);
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
@ -992,12 +992,11 @@ package example.format;
|
||||||
|
|
||||||
public class DecimalAnnotationFormatterFactory implements AnnotationFormatterFactory<DecimalFormat, Number> {
|
public class DecimalAnnotationFormatterFactory implements AnnotationFormatterFactory<DecimalFormat, Number> {
|
||||||
|
|
||||||
Formatter<Number> getFormatter(DecimalFormat annotation) {
|
Formatter<Number> getFormatter(DecimalFormat annotation) {
|
||||||
DecimalFormatter formatter = DecimalFormatter();
|
DecimalFormatter formatter = DecimalFormatter();
|
||||||
formatter.setPattern(annotation.value());
|
formatter.setPattern(annotation.value());
|
||||||
return formatter;
|
return formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
@ -1010,7 +1009,7 @@ package example.app;
|
||||||
public class MyModel {
|
public class MyModel {
|
||||||
|
|
||||||
@DecimalFormat("#,###")
|
@DecimalFormat("#,###")
|
||||||
private BigDecimal decimal;
|
private BigDecimal decimal;
|
||||||
|
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
|
|
@ -1031,9 +1030,9 @@ public class MyModel {
|
||||||
<programlisting language="java"><![CDATA[
|
<programlisting language="java"><![CDATA[
|
||||||
public interface FormatterRegistry {
|
public interface FormatterRegistry {
|
||||||
|
|
||||||
void add(Class<?> type, Formatter<?> targetFormatter);
|
void add(Class<?> type, Formatter<?> targetFormatter);
|
||||||
|
|
||||||
void add(AnnotationFormatterFactory<?, ?> factory);
|
void add(AnnotationFormatterFactory<?, ?> factory);
|
||||||
}]]>
|
}]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue