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

spring, spring-mvc

Solution

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;
    }

Problem

In spring, what is the difference between ``` modelMap.put("key",value); ``` and ``` modelMap.addAttribute("Key",value); ```

Original source