Package org.springframework.ui
Class ExtendedModelMap
- java.lang.Object
- java.util.AbstractMap<K,V>
- java.util.HashMap<K,V>
- java.util.LinkedHashMap<String,Object>
- org.springframework.ui.ModelMap
- org.springframework.ui.ExtendedModelMap
- Direct Known Subclasses:
BindingAwareModelMap
public class ExtendedModelMap extends ModelMap implements Model
Subclass ofModelMap
that implements theModel
interface. Java 5 specific like theModel
interface itself.This is an implementation class exposed to handler methods by Spring MVC, typically via a declaration of the
Model
interface. There is no need to build it within user code; a plainModelMap
or even a just a regularMap
with String keys will be good enough to return a user model.- Since:
- 2.5.1
- Author:
- Juergen Hoeller
- See Also:
- Serialized Form
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
Constructor Summary
Constructors Constructor Description ExtendedModelMap()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtendedModelMap
addAllAttributes(Collection<?> attributeValues)
Copy all attributes in the suppliedCollection
into thisMap
, using attribute name generation for each element.ExtendedModelMap
addAllAttributes(Map<String,?> attributes)
Copy all attributes in the suppliedMap
into thisMap
.ExtendedModelMap
addAttribute(Object attributeValue)
Add the supplied attribute to thisMap
using agenerated name
.ExtendedModelMap
addAttribute(String attributeName, Object attributeValue)
Add the supplied attribute under the supplied name.Map<String,Object>
asMap()
Return the current set of model attributes as a Map.ExtendedModelMap
mergeAttributes(Map<String,?> attributes)
Copy all attributes in the suppliedMap
into thisMap
, with existing objects of the same name taking precedence (i.e.Methods inherited from class org.springframework.ui.ModelMap
containsAttribute, getAttribute
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
Methods inherited from interface org.springframework.ui.Model
containsAttribute, getAttribute
Constructor Detail
ExtendedModelMap
public ExtendedModelMap()
Method Detail
addAttribute
public ExtendedModelMap addAttribute(String attributeName, @Nullable Object attributeValue)
Description copied from class:ModelMap
Add the supplied attribute under the supplied name.- Specified by:
addAttribute
in interfaceModel
- Overrides:
addAttribute
in classModelMap
- Parameters:
attributeName
- the name of the model attribute (nevernull
)attributeValue
- the model attribute value (can benull
)
addAttribute
public ExtendedModelMap addAttribute(Object attributeValue)
Description copied from class:ModelMap
Add the supplied attribute to thisMap
using agenerated 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 fornull
rather than for empty collections as is already done by JSTL tags.- Specified by:
addAttribute
in interfaceModel
- Overrides:
addAttribute
in classModelMap
- Parameters:
attributeValue
- the model attribute value (nevernull
)
addAllAttributes
public ExtendedModelMap addAllAttributes(@Nullable Collection<?> attributeValues)
Description copied from class:ModelMap
Copy all attributes in the suppliedCollection
into thisMap
, using attribute name generation for each element.- Specified by:
addAllAttributes
in interfaceModel
- Overrides:
addAllAttributes
in classModelMap
- See Also:
ModelMap.addAttribute(Object)
addAllAttributes
public ExtendedModelMap addAllAttributes(@Nullable Map<String,?> attributes)
Description copied from class:ModelMap
Copy all attributes in the suppliedMap
into thisMap
.- Specified by:
addAllAttributes
in interfaceModel
- Overrides:
addAllAttributes
in classModelMap
- See Also:
ModelMap.addAttribute(String, Object)
mergeAttributes
public ExtendedModelMap mergeAttributes(@Nullable Map<String,?> attributes)
Description copied from class:ModelMap
Copy all attributes in the suppliedMap
into thisMap
, with existing objects of the same name taking precedence (i.e. not getting replaced).- Specified by:
mergeAttributes
in interfaceModel
- Overrides:
mergeAttributes
in classModelMap