2024年3月6日
Spring Printer 类全路径: org.springframework.format.Printer 类作用: 对象转换成字符串 1 2 3 4 5 6 7 8 9 10 11 12 13 @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); }……
阅读全文
2024年3月6日
Spring Parser 类全路径: org.springframework.format.Parser 类作用: 字符串准换成 java 对象 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @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; } 类图……
阅读全文
2024年3月6日
Spring Formatter 类全路径: org.springframework.format.Formatter 1 2 3 public interface Formatter<T> extends Printer<T>, Parser<T> { } 该接口继承了 printer 和 parser 两个接口. 比较常见的有: DateFormatter 就是继承这个接口.……
阅读全文
2024年3月6日
Spring AnnotationFormatterFactory 类全路径: org.springframework.format.AnnotationFormatterFactory 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 public interface AnnotationFormatterFactory<A extends Annotation> { /** * The types of fields that may be annotated with the <A> 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……
阅读全文
2024年3月6日
Spring MillisecondInstantPrinter 类全路径: org.springframework.format.datetime.joda.MillisecondInstantPrinter 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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); } }……
阅读全文
2024年3月6日
Spring DateTimeParser 类全路径: org.springframework.format.datetime.joda.DateTimeParser 代码如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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); } }……
阅读全文
2024年3月6日
Spring DateTimeFormatAnnotationFormatterFactory 类全路径: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory 类图 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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()); // 判断时间格式是……
阅读全文
2024年3月6日
Spring scan Author: HuiFer 源码阅读仓库: SourceHot-Spring 解析 Spring 注解形式使用有下面两种方式 通过AnnotationConfigApplicationContext参数:扫描包 通过 xml 配置context:component-scan属性base-package 1 2 AnnotationConfigApplicationContext aac = new AnnotationConfigApplicationContext("com.huifer.source.spring.ann"); 1 2 <context:component-scan base-package="com.huifer.source.spring.ann"> </context:component-scan> 目标明确开始找入口方法 Annota……
阅读全文
2024年3月6日
Spring BeanFactory Author: HuiFer 源码阅读仓库: SourceHot-spring BeanFactory 概述 org.springframework.beans.factory.BeanFactory 类图 方法列表 贴出部分代码. 仅表示方法作用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public interface BeanFactory { // 从容器中根据beanname获取 Object getBean(String name) throws BeansException; // 延迟加载对象 <T> ObjectProvider<T> getBeanProvider(Class<T> requiredType); // 是否存在beanName boolean containsBean(String name); // 这个 beanName 是否是单例的. 映射成 bean boolean isSingleton(String name) throws NoSuchBeanDefinitionException; // 是否多例. boolean isPrototype(String name) throws NoSuchBeanDefinitionException; // 类……
阅读全文
2024年3月6日
Spring SystemPropertyUtils spring 中获取系统属性的工具类 内部属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /** * * Prefix for system property placeholders: "${". * 前缀占位符 * */ public static final String PLACEHOLDER_PREFIX = "${"; /** * Suffix for system property placeholders: "}". * 后缀占位符 * */ public static final String PLACEHOLDER_SUFFIX = "}"; /** * Value separator for system property placeholders: ":". * 值分割符号 * */ public static final String VALUE_SEPARATOR = ":"; /** * 占位符解析类 */ private static final PropertyPlaceholderHelper strictHelper = new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, false);……
阅读全文