SpringFramework核心技术三:Spring时间处理和类型转换
使用 在(1)中,我们学习了蛮多的基本概念,在(2)中咱们看一下如何使用的问题。 一、以编程方式使用ConversionService 要以编程方式使用ConversionService实例,只需为其他bean注入一个引用即可: @Service public class MyService { @Autowired public MyService(ConversionService conversionService) { this.conversionService = conversionService; } public void doIt() { this.conversionService.convert(...) } } 对于大多数用例,可以使用convert指定targetType的方法,但它不适用于更复杂的类型,如参数化元素的集合。如果你想转换List的Integer到List的String程序,例如,你需要提供的源和目标类型的正式定义。 幸运的是,TypeDescriptor提供了各种选项来简单明了: DefaultConversionService cs = n...



