Class RedirectAttributesModelMap
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<String,Object>
org.springframework.ui.ModelMap
org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,,Object> Model,RedirectAttributes
A
ModelMap implementation of RedirectAttributes that formats
values as Strings using a DataBinder. Also provides a place to store
flash attributes so they can survive a redirect without the need to be
embedded in the redirect URL.- Since:
- 3.1
- Author:
- Rossen Stoyanchev
- See Also:
-
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
ConstructorsConstructorDescriptionDefault constructor without a DataBinder.RedirectAttributesModelMap(DataBinder dataBinder) Constructor with a DataBinder. -
Method Summary
Modifier and TypeMethodDescriptionaddAllAttributes(Collection<?> attributeValues) Copy all attributes in the suppliedCollectioninto thisMap, using attribute name generation for each element.addAllAttributes(Map<String, ?> attributes) Copy all attributes in the suppliedMapinto thisMap.addAttribute(Object attributeValue) Add the supplied attribute to thisMapusing agenerated name.addAttribute(String attributeName, Object attributeValue) Add the supplied attribute under the supplied name.addFlashAttribute(Object attributeValue) Add the given flash storage using agenerated name.addFlashAttribute(String attributeName, Object attributeValue) Add the given flash attribute.asMap()Return the current set of model attributes as a Map.Return the attributes candidate for flash storage or an empty Map.mergeAttributes(Map<String, ?> attributes) Copy all attributes in the suppliedMapinto thisMap, with existing objects of the same name taking precedence (i.e.voidMethods inherited from class org.springframework.ui.ModelMap
containsAttribute, getAttributeMethods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from interface org.springframework.ui.Model
containsAttribute, getAttribute
-
Constructor Details
-
RedirectAttributesModelMap
public RedirectAttributesModelMap()Default constructor without a DataBinder. Attribute values are converted to String viaAbstractMap.toString(). -
RedirectAttributesModelMap
Constructor with a DataBinder.- Parameters:
dataBinder- used to format attribute values as Strings
-
-
Method Details
-
getFlashAttributes
Return the attributes candidate for flash storage or an empty Map.- Specified by:
getFlashAttributesin interfaceRedirectAttributes
-
addAttribute
public RedirectAttributesModelMap addAttribute(String attributeName, @Nullable Object attributeValue) Add the supplied attribute under the supplied name.Formats the attribute value as a String before adding it.
- Specified by:
addAttributein interfaceModel- Specified by:
addAttributein interfaceRedirectAttributes- Overrides:
addAttributein classModelMap- Parameters:
attributeName- the name of the model attribute (nevernull)attributeValue- the model attribute value (can benull)
-
addAttribute
Add the supplied attribute to thisMapusing agenerated name.Note: Empty
Collectionsare not added to the model when using this method because we cannot correctly determine the true convention name. View code should check fornullrather than for empty collections as is already done by JSTL tags.Formats the attribute value as a String before adding it.
- Specified by:
addAttributein interfaceModel- Specified by:
addAttributein interfaceRedirectAttributes- Overrides:
addAttributein classModelMap- Parameters:
attributeValue- the model attribute value (nevernull)
-
addAllAttributes
Copy all attributes in the suppliedCollectioninto thisMap, using attribute name generation for each element.Each attribute value is formatted as a String before being added.
- Specified by:
addAllAttributesin interfaceModel- Specified by:
addAllAttributesin interfaceRedirectAttributes- Overrides:
addAllAttributesin classModelMap- See Also:
-
addAllAttributes
Copy all attributes in the suppliedMapinto thisMap.Each attribute value is formatted as a String before being added.
- Specified by:
addAllAttributesin interfaceModel- Overrides:
addAllAttributesin classModelMap- See Also:
-
mergeAttributes
Copy all attributes in the suppliedMapinto thisMap, with existing objects of the same name taking precedence (i.e. not getting replaced).Each attribute value is formatted as a String before being merged.
- Specified by:
mergeAttributesin interfaceModel- Specified by:
mergeAttributesin interfaceRedirectAttributes- Overrides:
mergeAttributesin classModelMap
-
asMap
Description copied from interface:ModelReturn the current set of model attributes as a Map. -
put
The value is formatted as a String before being added.
-
putAll
Each value is formatted as a String before being added.
-
addFlashAttribute
Description copied from interface:RedirectAttributesAdd the given flash attribute.- Specified by:
addFlashAttributein interfaceRedirectAttributes- Parameters:
attributeName- the attribute name; nevernullattributeValue- the attribute value; may benull
-
addFlashAttribute
Description copied from interface:RedirectAttributesAdd the given flash storage using agenerated name.- Specified by:
addFlashAttributein interfaceRedirectAttributes- Parameters:
attributeValue- the flash attribute value; nevernull
-