63 Star 428 Fork 156

huifer/Code-Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Spring-Converter.md 1.26 KB
一键复制 编辑 原始数据 按行查看 历史

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

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pychfarm_admin/code-analysis.git
git@gitee.com:pychfarm_admin/code-analysis.git
pychfarm_admin
code-analysis
Code-Analysis
v0.0.15

搜索帮助