spring自定义属性编辑器
文章目录
spring自定义属性编辑器
属性编辑器用来解析bean的配置文件中的属性标签,spring的BeanWrapperImpl默认会注册CustomCollectionEditor(集合)、CustomMapEditor(Map)、CurrencyEditor(货币)、ByteArrayPropertyEditor等,可以使用CustomEditorConfigurer来注册属性编辑器,CustomEditorConfigurer实现了BeanFactoryPostProcessor接口,由spring容器自动检测并执行
步骤
- 创建一个实现PropertyEditorRegistrar接口的类,重写registerCustomEditors方法,负责向spring容器注册属性编辑器
- 将PropertyEditorRegistrar实现类作为bean进行注册
- 配置CustomEditorConfigurer这个bean,并写入属性propertyEditorRegistrars中
https://zhhll.icu/2021/框架/spring/基础/17.spring自定义属性编辑器/
本文由mdnice多平台发布
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论