Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modelMap.put() v/s modelMap.addAttribute()

In spring, what is the difference between

modelMap.put("key",value);

and

modelMap.addAttribute("Key",value);
like image 438
user1969655 Avatar asked Oct 22 '22 13:10

user1969655


1 Answers

addAttributes implies check for not null in attribute name -> see sources

 /**
     * Add the supplied attribute under the supplied name.
     * @param attributeName the name of the model attribute (never <code>null</code>)
     * @param attributeValue the model attribute value (can be <code>null</code>)
     */
    public ModelMap addAttribute(String attributeName, Object attributeValue) {
        Assert.notNull(attributeName, "Model attribute name must not be null");
        put(attributeName, attributeValue);
        return this;
    }
like image 129
user2088476 Avatar answered Nov 02 '22 14:11

user2088476