propertyEditor

2023-11-02 23:44
文章标签 propertyeditor

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/334113

相关文章

Eclipse(properties)插件:PropertyEditor在线安装

随时随地技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666) 转自:http://blog.csdn.net/elite_1989/article/details/12972177 在编辑一些简体中文、繁体中文等 Unicode文本时,不必再使用native2ascii编码了。 您可以通过Eclipse中的软件升级(Software Update)安装此插件,

Spring 类型转换、数值绑定与验证(二)—PropertyEditor与Conversion

Spring 中,属性类型转换是在将数值绑定到目标对象时完成的。例如在创建ApplicationContext 容器时,将XML配置的bean 转换成Java类型对象,主要是借助了PropertyEditor类,而在Spring MVC 的Controller的请求参数转化为特定类型时,我们也可以自定义转化器Convert并注册来完成转换。以下是Spring相关源码分析。 1 Property

9.自定义属性编辑器PropertyEditor(主要针对的是自定义的类,不常用,还是用ref注入的多见)

作用:Spring中我们可以使用属性编辑器来`将特定的字符串转换为对象`通过set注入时,想简单的这种是spring提供好了属性编辑器,将value="20"中的字符串转换成了int类型的20<property name="age" value="20"></property>但是像下面的这种,value="甘肃兰州",spring是没办法自动将字符串转为Address类型,所以需要我们自己