org.springframework.beans.propertyeditors

## 类 CustomMapEditor

- java.lang.Object
- - java.beans.PropertyEditorSupport
  - - org.springframework.beans.propertyeditors.CustomMapEditor

- 所有已实现的接口:
    PropertyEditor

      public class CustomMapEditor
      extends PropertyEditorSupport

  Property editor for Maps, converting any source Map to a given target Map type.
  从以下版本开始:
    2.0.1
  作者:
    Juergen Hoeller
  另请参阅:
    `Map`, `SortedMap`

- - ### 构造器概要

    构造器
    构造器和说明
    `CustomMapEditor(Class<? extends Map> mapType)` Create a new CustomMapEditor for the given target type, keeping an incoming `null` as-is.
    `CustomMapEditor(Class<? extends Map> mapType, boolean nullAsEmptyMap)` Create a new CustomMapEditor for the given target type.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected boolean` | `alwaysCreateNewMap()` Return whether to always create a new Map, even if the type of the passed-in Map already matches.
    `protected Object` | `convertKey(Object key)` Hook to convert each encountered Map key.
    `protected Object` | `convertValue(Object value)` Hook to convert each encountered Map value.
    `protected Map<Object,Object>` | `createMap(Class<? extends Map> mapType, int initialCapacity)` Create a Map of the given type, with the given initial capacity (if supported by the Map type).
    `String` | `getAsText()` This implementation returns `null` to indicate that there is no appropriate text representation.
    `void` | `setAsText(String text)` Convert the given text value to a Map with a single element.
    `void` | `setValue(Object value)` Convert the given value to a Map of the target type.

    - ### 从类继承的方法 java.beans.PropertyEditorSupport

      `addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, supportsCustomEditor`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### CustomMapEditor

          public CustomMapEditor(Class<? extends Map> mapType)

      Create a new CustomMapEditor for the given target type, keeping an incoming `null` as-is.
      参数:
        `mapType` - the target type, which needs to be a sub-interface of Map or a concrete Map class
      另请参阅:
        `Map`, `HashMap`, `TreeMap`, `LinkedHashMap`

    - #### CustomMapEditor

          public CustomMapEditor(Class<? extends Map> mapType,
                                 boolean nullAsEmptyMap)

      Create a new CustomMapEditor for the given target type.

      If the incoming value is of the given type, it will be used as-is. If it is a different Map type or an array, it will be converted to a default implementation of the given Map type. If the value is anything else, a target Map with that single value will be created.

      The default Map implementations are: TreeMap for SortedMap, and LinkedHashMap for Map.

      参数:
        `mapType` - the target type, which needs to be a sub-interface of Map or a concrete Map class
        `nullAsEmptyMap` - ap whether to convert an incoming `null` value to an empty Map (of the appropriate type)
      另请参阅:
        `Map`, `TreeMap`, `LinkedHashMap`

  - ### 方法详细资料

    - #### setAsText

          public void setAsText(String text)
                         throws IllegalArgumentException

      Convert the given text value to a Map with a single element.
      指定者:
        `setAsText` 在接口中 `PropertyEditor`
      覆盖:
        `setAsText` 在类中 `PropertyEditorSupport`
      抛出:
        `IllegalArgumentException`

    - #### setValue

          public void setValue(@Nullable
                               Object value)

      Convert the given value to a Map of the target type.
      指定者:
        `setValue` 在接口中 `PropertyEditor`
      覆盖:
        `setValue` 在类中 `PropertyEditorSupport`

    - #### createMap

          protected Map<Object,Object> createMap(Class<? extends Map> mapType,
                                                 int initialCapacity)

      Create a Map of the given type, with the given initial capacity (if supported by the Map type).
      参数:
        `mapType` - a sub-interface of Map
        `initialCapacity` - the initial capacity
      返回:
        the new Map instance

    - #### alwaysCreateNewMap

          protected boolean alwaysCreateNewMap()

      Return whether to always create a new Map, even if the type of the passed-in Map already matches.

      Default is "false"; can be overridden to enforce creation of a new Map, for example to convert elements in any case.

      另请参阅:
        `convertKey(java.lang.Object)`, `convertValue(java.lang.Object)`

    - #### convertKey

          protected Object convertKey(Object key)

      Hook to convert each encountered Map key. The default implementation simply returns the passed-in key as-is.

      Can be overridden to perform conversion of certain keys, for example from String to Integer.

      Only called if actually creating a new Map! This is by default not the case if the type of the passed-in Map already matches. Override `alwaysCreateNewMap()` to enforce creating a new Map in every case.

      参数:
        `key` - the source key
      返回:
        the key to be used in the target Map
      另请参阅:
        `alwaysCreateNewMap()`

    - #### convertValue

          protected Object convertValue(Object value)

      Hook to convert each encountered Map value. The default implementation simply returns the passed-in value as-is.

      Can be overridden to perform conversion of certain values, for example from String to Integer.

      Only called if actually creating a new Map! This is by default not the case if the type of the passed-in Map already matches. Override `alwaysCreateNewMap()` to enforce creating a new Map in every case.

      参数:
        `value` - the source value
      返回:
        the value to be used in the target Map
      另请参阅:
        `alwaysCreateNewMap()`

    - #### getAsText

          @Nullable
          public String getAsText()

      This implementation returns `null` to indicate that there is no appropriate text representation.
      指定者:
        `getAsText` 在接口中 `PropertyEditor`
      覆盖:
        `getAsText` 在类中 `PropertyEditorSupport`