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

use*_*655 5 spring spring-mvc jakarta-ee

春天和春天有什么区别

modelMap.put("key",value);
Run Code Online (Sandbox Code Playgroud)

modelMap.addAttribute("Key",value);
Run Code Online (Sandbox Code Playgroud)

use*_*476 5

addAttributes 意味着检查属性名称中是否不为空 -> 请参阅来源

 /**
     * 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;
    }
Run Code Online (Sandbox Code Playgroud)