Top Description Methods
org.springframework.ui

public Interface Model

Known Direct Implementers
org.springframework.ui.ConcurrentModel, org.springframework.ui.ExtendedModelMap
Imports
java.util.Collection, .Map, org.springframework.lang.Nullable

Interface that defines a holder for model attributes.

Primarily designed for adding attributes to the model.

Allows for accessing the overall model as a java.util.Map.

Author
Juergen Hoeller
Since
2.5.1

Method Summary

Modifier and TypeMethod and Description
public Model
addAllAttributes(Collection<?> attributeValues)

Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.

public Model
addAllAttributes(Map<String, ?> attributes)

Copy all attributes in the supplied Map into this Map.

public Model
addAttribute(String
the name of the model attribute (never null)
attributeName
,
Object
the model attribute value (can be null)
attributeValue
)

Add the supplied attribute under the supplied name.

public Model
addAttribute(Object
the model attribute value (never null)
attributeValue
)

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

public Map<String, Object>
asMap()

Return the current set of model attributes as a Map.

public boolean

Returns:

whether this model contains a corresponding attribute
containsAttribute
(String
the name of the model attribute (never null)
attributeName
)

Does this model contain an attribute of the given name?

public Object

Returns:

the corresponding attribute value, or null if none
getAttribute
(String
the name of the model attribute (never null)
attributeName
)

Return the attribute value for the given name, if any.

public Model
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).

Method Detail

addAllAttributesback to summary
public Model addAllAttributes(Collection<?> attributeValues)

Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.

See Also
addAttribute(Object)
addAllAttributesback to summary
public Model addAllAttributes(Map<String, ?> attributes)

Copy all attributes in the supplied Map into this Map.

See Also
addAttribute(String, Object)
addAttributeback to summary
public Model addAttribute(String attributeName, Object attributeValue)

Add the supplied attribute under the supplied name.

Parameters
attributeName:String

the name of the model attribute (never null)

attributeValue:Object

the model attribute value (can be null)

addAttributeback to summary
public Model 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.

Parameters
attributeValue:Object

the model attribute value (never null)

asMapback to summary
public Map<String, Object> asMap()

Return the current set of model attributes as a Map.

containsAttributeback to summary
public boolean containsAttribute(String attributeName)

Does this model contain an attribute of the given name?

Parameters
attributeName:String

the name of the model attribute (never null)

Returns:boolean

whether this model contains a corresponding attribute

getAttributeback to summary
public Object getAttribute(String attributeName)

Return the attribute value for the given name, if any.

Parameters
attributeName:String

the name of the model attribute (never null)

Returns:Object

the corresponding attribute value, or null if none

Annotations
@Nullable
Since
5.2
mergeAttributesback to summary
public Model 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).