1 Star 0 Fork 156

南风不竞 / Spring-Analysis

forked from huifer / Code-Analysis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Spring-Converter.md 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
huifer 提交于 2020-11-09 16:53 . :fire:core/ convert + attributeAccessor

Spring Converter

  • 类全路径: org.springframework.core.convert.converter.Converter
  • 类作用: 转换接口
@FunctionalInterface
public interface Converter<S, T> {

	/**
	 * Convert the source object of type {@code S} to target type {@code T}.
	 * 从 source 转换成 t 
	 * @param source the source object to convert, which must be an instance of {@code S} (never {@code null})
	 * @return the converted object, which must be an instance of {@code T} (potentially {@code null})
	 * @throws IllegalArgumentException if the source cannot be converted to the desired target type
	 */
	@Nullable
	T convert(S source);

}
  • 类图

converter

接下来我们看几个类来了解一下具体的实现

ObjectToStringConverter

final class ObjectToStringConverter implements Converter<Object, String> {

   @Override
   public String convert(Object source) {
      return source.toString();
   }

}

StringToCharsetConverter

class StringToCharsetConverter implements Converter<String, Charset> {

   @Override
   public Charset convert(String source) {
      return Charset.forName(source);
   }

}
  • 其他的子类各位读者请自行阅读.

    包路径: org.springframework.core.convert.support

Java
1
https://gitee.com/limengcanyu/spring-analysis.git
git@gitee.com:limengcanyu/spring-analysis.git
limengcanyu
spring-analysis
Spring-Analysis
master

搜索帮助