org.springframework.ui

## 类 ModelMap

- java.lang.Object
- - java.util.AbstractMap<K,V>
  - - java.util.HashMap<K,V>
    - - java.util.LinkedHashMap<String,Object>
      - - org.springframework.ui.ModelMap

- 所有已实现的接口:
    Serializable, Cloneable, Map<String,Object>
  直接已知子类:
    ExtendedModelMap

      public class ModelMap
      extends LinkedHashMap<String,Object>

  Implementation of `Map` for use when building model data for use with UI tools. Supports chained calls and generation of model attribute names.

  This class serves as generic model holder for Servlet MVC but is not tied to it. Check out the `Model` interface for an interface variant.

  从以下版本开始:
    2.0
  作者:
    Rob Harrop, Juergen Hoeller
  另请参阅:
    `Conventions.getVariableName(java.lang.Object)`, `org.springframework.web.servlet.ModelAndView`, 序列化表格

- - ### 嵌套类概要

    - ### 从类继承的嵌套类/接口 java.util.AbstractMap

      `AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

  - ### 构造器概要

    构造器
    构造器和说明
    `ModelMap()` Construct a new, empty `ModelMap`.
    `ModelMap(Object attributeValue)` Construct a new `ModelMap` containing the supplied attribute.
    `ModelMap(String attributeName, Object attributeValue)` Construct a new `ModelMap` containing the supplied attribute under the supplied name.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `ModelMap` | `addAllAttributes(Collection<?> attributeValues)` Copy all attributes in the supplied `Collection` into this `Map`, using attribute name generation for each element.
    `ModelMap` | `addAllAttributes(Map<String,?> attributes)` Copy all attributes in the supplied `Map` into this `Map`.
    `ModelMap` | `addAttribute(Object attributeValue)` Add the supplied attribute to this `Map` using a `generated name`.
    `ModelMap` | `addAttribute(String attributeName, Object attributeValue)` Add the supplied attribute under the supplied name.
    `boolean` | `containsAttribute(String attributeName)` Does this model contain an attribute of the given name?
    `ModelMap` | `mergeAttributes(Map<String,?> attributes)` Copy all attributes in the supplied `Map` into this `Map`, with existing objects of the same name taking precedence (i.e. not getting replaced).

    - ### 从类继承的方法 java.util.LinkedHashMap

      `clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values`

    - ### 从类继承的方法 java.util.HashMap

      `clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size`

    - ### 从类继承的方法 java.util.AbstractMap

      `equals, hashCode, toString`

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

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### 从接口继承的方法 java.util.Map

      `compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size`

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

    - #### ModelMap

          public ModelMap()

      Construct a new, empty `ModelMap`.

    - #### ModelMap

          public ModelMap(String attributeName,
                          @Nullable
                          Object attributeValue)

      Construct a new `ModelMap` containing the supplied attribute under the supplied name.
      另请参阅:
        `addAttribute(String, Object)`

    - #### ModelMap

          public ModelMap(Object attributeValue)

      Construct a new `ModelMap` containing the supplied attribute. Uses attribute name generation to generate the key for the supplied model object.
      另请参阅:
        `addAttribute(Object)`

  - ### 方法详细资料

    - #### addAttribute

          public ModelMap addAttribute(String attributeName,
                                       @Nullable
                                       Object attributeValue)

      Add the supplied attribute under the supplied name.
      参数:
        `attributeName` - the name of the model attribute (never `null`)
        `attributeValue` - the model attribute value (can be `null`)

    - #### addAttribute

          public ModelMap addAttribute(Object attributeValue)

      Add the supplied attribute to this `Map` using a `generated name`.

      Note: Empty `Collections` are not added to the model when using this method because we cannot correctly determine the true convention name. View code should check for `null` rather than for empty collections as is already done by JSTL tags.

      参数:
        `attributeValue` - the model attribute value (never `null`)

    - #### addAllAttributes

          public ModelMap addAllAttributes(@Nullable
                                           Collection<?> attributeValues)

      Copy all attributes in the supplied `Collection` into this `Map`, using attribute name generation for each element.
      另请参阅:
        `addAttribute(Object)`

    - #### addAllAttributes

          public ModelMap addAllAttributes(@Nullable
                                           Map<String,?> attributes)

      Copy all attributes in the supplied `Map` into this `Map`.
      另请参阅:
        `addAttribute(String, Object)`

    - #### mergeAttributes

          public ModelMap mergeAttributes(@Nullable
                                          Map<String,?> attributes)

      Copy all attributes in the supplied `Map` into this `Map`, with existing objects of the same name taking precedence (i.e. not getting replaced).

    - #### containsAttribute

          public boolean containsAttribute(String attributeName)

      Does this model contain an attribute of the given name?
      参数:
        `attributeName` - the name of the model attribute (never `null`)
      返回:
        whether this model contains a corresponding attribute