本文主要是介绍propertyEditor,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
类型转化类
1、JDK自带的工具类
继承PropertyEditorSupport,实现PropertyEditor
2、向Spring中(CustomEditorConfigurer)注册PropertyEditor
最终实现 @Value的功能
spring自带的类型转化类
1、实现ConditionalGenericConverter
2、向DefaultConversionService注册该实现类
整合了PropertyEditor和ConversionService的功能
SimpleTypeConverter converter = new SimpleTypeConverter();
converter.registerCustomEditor(User.class,new StringToUserPropertyEditor());
User user = converter.convertIfNecessary("12", User.class);
System.out.println(user);
这篇关于propertyEditor的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!