首页 > 软件开发 > 编程语言 >

运用 PropertyEditorRegistrar

来源:互联网 2023-03-17 00:26:44 363

运用PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

工具/原料

  • spring
  • IntelliJ

方法/步骤

  • 1

    使用Spring容器注册属性编辑器的另一种机制是创建和使用PropertyEditorRegistrar。当您需要在几种不同情况下使用同一组属性编辑器时,此接口特别有用。您可以编写相应的注册商,并在每种情况下重复使用它。Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 2

    PropertyEditorRegistrar实例与一个名为PropertyEditorRegistry的接口一起工作,该接口由SpringBeanWrapper(和DataBinder)实现。PropertyEditorRegistrar当与CustomEditorConfigurer一起使用时,实例特别方便,它暴露了一个名为的属性setPropertyEditorRegistrars(..)。以这种方式PropertyEditorRegistrar添加到a的实例CustomEditorConfigurer可以很容易地与之共享DataBinder和Spring MVC控制器。Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 3

    此外,它避免了在自定义编辑器上进行同步的需要:APropertyEditorRegistrar期望PropertyEditor为每个bean创建尝试创建新的实例。Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 4

    以下示例显示如何创建自己的PropertyEditorRegistrar实现:Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 5

    在实现该registerCustomEditors(..)方法时,它会创建每个属性编辑器的新实例。Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 5该信息未经许可获取自百度经验
  • 6

    示例显示了如何配置CustomEditorConfigurer和注入我们的实例CustomPropertyEditorRegistrar:Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 7

    PropertyEditorRegistrars结合使用数据绑定Controllers(例如SimpleFormController)可以非常方便。以下示例PropertyEditorRegistrar在initBinder(..)方法的实现中使用Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 8

    这种 PropertyEditor 注册方式可以导致简洁的代码(实现 initBinder(..) 只有一行),并允许将通用 PropertyEditor 注册代码封装在一个类中,然后 Controllers 根据需要共享 。Sg5办公区 - 实用经验教程分享!

    运用 PropertyEditorRegistrarSg5办公区 - 实用经验教程分享!

  • 以上方法由办公区教程网编辑摘抄自百度经验可供大家参考!Sg5办公区 - 实用经验教程分享!


    标签: JAVA编程语言

    办公区 Copyright © 2016-2023 www.bgqu.net. Some Rights Reserved. 备案号:湘ICP备2020019561号统计代码