Merge pull request #80 from huifer/master

Spring source code
pull/81/head
Yang Libin 4 years ago committed by GitHub
commit 52295fff0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,29 +60,34 @@
### Spring 类解析
- [Spring 自定义标签解析](/docs/Spring/clazz/Spring-Custom-label-resolution.md)
- [Spring Scan 包扫描](/docs/Spring/clazz/Spring-scan.md)
- [Spring 注解工具类](/docs/Spring/clazz/Spring-AnnotationUtils.md)
- [Spring 别名注册](/docs/Spring/clazz/Spring-SimpleAliasRegistry.md)
- [Spring 标签解析类](/docs/Spring/clazz/Spring-BeanDefinitionParserDelegate.md)
- [Spring ApplicationListener](/docs/Spring/clazz/Spring-ApplicationListener.md)
- [Spring messageSource](/docs/Spring/clazz/Spring-MessageSource.md)
- [Spring 自定义属性解析器](/docs/Spring/clazz/Spring-Custom-attribute-resolver.md)
- [Spring 排序工具](/docs/Spring/clazz/Spring-OrderUtils.md)
- [Spring-import 注解](/docs/Spring/clazz/Spring-Import.md)
- [Spring-定时任务](/docs/Spring/clazz/Spring-Scheduling.md)
- [Spring StopWatch](/docs/Spring/clazz/Spring-StopWatch.md)
- [Spring 元数据](/docs/Spring/clazz/Spring-Metadata.md)
- [Spring 条件接口](/docs/Spring/clazz/Spring-Conditional.md)
- [Spring MultiValueMap](/docs/Spring/clazz/Spring-MultiValueMap.md)
- [Spring MethodOverride](/docs/Spring/clazz/Spring-MethodOverride.md)
- [Spring BeanDefinitionReaderUtils](/docs/Spring/clazz/Spring-BeanDefinitionReaderUtils.md)
- [Spring PropertyPlaceholderHelper](/docs/Spring/clazz/Spring-PropertyPlaceholderHelper.md)
- [Spring PropertySource](/docs/Spring/clazz/PropertySource)
- [Spring PlaceholderResolver](/docs/Spring/clazz/PlaceholderResolver)
* [Spring 自定义标签解析](/docs/Spring/clazz/Spring-Custom-label-resolution.md)
* [Spring Scan 包扫描](/docs/Spring/clazz/Spring-scan.md)
* [Spring 注解工具类](/docs/Spring/clazz/Spring-AnnotationUtils.md)
* [Spring 别名注册](/docs/Spring/clazz/Spring-SimpleAliasRegistry.md)
* [Spring 标签解析类](/docs/Spring/clazz/Spring-BeanDefinitionParserDelegate.md)
* [Spring ApplicationListener](/docs/Spring/clazz/Spring-ApplicationListener.md)
* [Spring messageSource](/docs/Spring/clazz/Spring-MessageSource.md)
* [Spring 自定义属性解析器](/docs/Spring/clazz/Spring-Custom-attribute-resolver.md)
* [Spring 排序工具](/docs/Spring/clazz/Spring-OrderUtils.md)
* [Spring-import注解](/docs/Spring/clazz/Spring-Import.md)
* [Spring-定时任务](/docs/Spring/clazz/Spring-Scheduling.md)
* [Spring StopWatch](/docs/Spring/clazz/Spring-StopWatch.md)
* [Spring 元数据](/docs/Spring/clazz/Spring-Metadata.md)
* [Spring 条件接口](/docs/Spring/clazz/Spring-Conditional.md)
* [Spring MultiValueMap](/docs/Spring/clazz/Spring-MultiValueMap.md)
* [Spring MethodOverride](/docs/Spring/clazz/Spring-MethodOverride.md)
* [Spring BeanDefinitionReaderUtils](/docs/Spring/clazz/Spring-BeanDefinitionReaderUtils.md)
* [Spring PropertyPlaceholderHelper](/docs/Spring/clazz/Spring-PropertyPlaceholderHelper.md)
* [Spring PropertySource](/docs/Spring/clazz/PropertySource)
* [Spring PlaceholderResolver](/docs/Spring/clazz/PlaceholderResolver)
* [Spring-AnnotationFormatterFactory](/docs/Spring/clazz/format/Spring-AnnotationFormatterFactory.md)
* [Spring-Formatter](/docs/Spring/clazz/format/Spring-Formatter.md)
* [Spring-Parser](/docs/Spring/clazz/format/Spring-Parser.md)
* [Spring-Printer](/docs/Spring/clazz/format/Spring-Printer.md)
### Spring5 新特性

@ -0,0 +1,63 @@
# Spring DateTimeFormatAnnotationFormatterFactory
- 类全路径: `org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory`
- 类图
![EmbeddedValueResolutionSupport](/images/spring/DateTimeFormatAnnotationFormatterFactory.png)
```java
public class DateTimeFormatAnnotationFormatterFactory extends EmbeddedValueResolutionSupport
implements AnnotationFormatterFactory<DateTimeFormat> {
/**
* 字段类型
*/
private static final Set<Class<?>> FIELD_TYPES;
@Override
public Set<Class<?>> getFieldTypes() {
return FIELD_TYPES;
}
@Override
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
return getFormatter(annotation, fieldType);
}
@Override
public Parser<?> getParser(DateTimeFormat annotation, Class<?> fieldType) {
return getFormatter(annotation, fieldType);
}
protected Formatter<Date> getFormatter(DateTimeFormat annotation, Class<?> fieldType) {
DateFormatter formatter = new DateFormatter();
// style
String style = resolveEmbeddedValue(annotation.style());
// 判断时间格式是否村子啊
if (StringUtils.hasLength(style)) {
formatter.setStylePattern(style);
}
// iso 设置
formatter.setIso(annotation.iso());
// date time pattern
String pattern = resolveEmbeddedValue(annotation.pattern());
// 设置
if (StringUtils.hasLength(pattern)) {
formatter.setPattern(pattern);
}
return formatter;
}
static {
Set<Class<?>> fieldTypes = new HashSet<>(4);
// 加入字段类型
fieldTypes.add(Date.class);
fieldTypes.add(Calendar.class);
fieldTypes.add(Long.class);
FIELD_TYPES = Collections.unmodifiableSet(fieldTypes);
}
}
```

@ -0,0 +1,29 @@
# Spring DateTimeParser
- 类全路径: `org.springframework.format.datetime.joda.DateTimeParser`
- 代码如下
```java
public final class DateTimeParser implements Parser<DateTime> {
private final DateTimeFormatter formatter;
/**
* Create a new DateTimeParser.
* @param formatter the Joda DateTimeFormatter instance
*/
public DateTimeParser(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public DateTime parse(String text, Locale locale) throws ParseException {
// DateTimeFormatter 转换字符串事件类型
return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseDateTime(text);
}
}
```

@ -0,0 +1,28 @@
# Spring MillisecondInstantPrinter
- 类全路径: `org.springframework.format.datetime.joda.MillisecondInstantPrinter`
```java
public final class MillisecondInstantPrinter implements Printer<Long> {
private final DateTimeFormatter formatter;
/**
* Create a new ReadableInstantPrinter.
* @param formatter the Joda DateTimeFormatter instance
*/
public MillisecondInstantPrinter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
@Override
public String print(Long instant, Locale locale) {
// DateTimeFormatter .print
return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(instant);
}
}
```

@ -0,0 +1,42 @@
# Spring AnnotationFormatterFactory
- 类全路径: `org.springframework.format.AnnotationFormatterFactory`
```java
public interface AnnotationFormatterFactory<A extends Annotation> {
/**
* The types of fields that may be annotated with the &lt;A&gt; annotation.
* 字段类型
*/
Set<Class<?>> getFieldTypes();
/**
* Get the Printer to print the value of a field of {@code fieldType} annotated with
* {@code annotation}.
* <p>If the type T the printer accepts is not assignable to {@code fieldType}, a
* coercion from {@code fieldType} to T will be attempted before the Printer is invoked.
* 通过注解和字段类型获取输出接口
* @param annotation the annotation instance
* @param fieldType the type of field that was annotated
* @return the printer
*/
Printer<?> getPrinter(A annotation, Class<?> fieldType);
/**
* Get the Parser to parse a submitted value for a field of {@code fieldType}
* annotated with {@code annotation}.
* <p>If the object the parser returns is not assignable to {@code fieldType},
* a coercion to {@code fieldType} will be attempted before the field is set.
* 通过注解和字段类型获取解析接口
* @param annotation the annotation instance
* @param fieldType the type of field that was annotated
* @return the parser
*/
Parser<?> getParser(A annotation, Class<?> fieldType);
}
```

@ -0,0 +1,11 @@
# Spring Formatter
- 类全路径: `org.springframework.format.Formatter`
```java
public interface Formatter<T> extends Printer<T>, Parser<T> {
}
```
- 该接口继承了 printer 和 parser 两个接口.
- 比较常见的有: `DateFormatter` 就是继承这个接口.

@ -0,0 +1,27 @@
# Spring Parser
- 类全路径: `org.springframework.format.Parser`
- 类作用: 字符串准换成java对象
```java
@FunctionalInterface
public interface Parser<T> {
/**
* Parse a text String to produce a T.
* 将字符串转换成对象
* @param text the text string
* @param locale the current user locale
* @return an instance of T
* @throws ParseException when a parse exception occurs in a java.text parsing library
* @throws IllegalArgumentException when a parse exception occurs
*/
T parse(String text, Locale locale) throws ParseException;
}
```
- 类图
![Parser](/images/spring/Parser.png)

@ -0,0 +1,20 @@
# Spring Printer
- 类全路径: `org.springframework.format.Printer`
- 类作用: 对象转换成字符串
```java
@FunctionalInterface
public interface Printer<T> {
/**
* Print the object of type T for display.
* 打印对象
* @param object the instance to print
* @param locale the current user locale
* @return the printed text string
*/
String print(T object, Locale locale);
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Loading…
Cancel
Save