类 ModelMap

    • 构造器详细资料

      • ModelMap

        public ModelMap()
        Construct a new, empty ModelMap.
      • 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)
      • 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
      • getAttribute

        @Nullable
        public Object getAttribute​(String attributeName)
        Return the attribute value for the given name, if any.
        参数:
        attributeName - the name of the model attribute (never null)
        返回:
        the corresponding attribute value, or null if none
        从以下版本开始:
        5.2