2013-04-01 19 views

回答

3

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; 
    } 
0
addAttribute(String attributeName, Object attributeValue) 

在提供的名稱下添加提供的屬性。

put(String attributeName, Object attributeValue) 

將指定值與 此映射指定的attributeName。如果映射先前包含 attributeName的映射,則舊值將被替換。

的addAttribute是增加價值,並把用於添加或更換

如果我們考慮到有關Java API春

java.lang.Object繼承 java.util.AbstractMap中 的java.util.HashMap 的java .util.LinkedHashMap org.springframework.ui.ModelMap

Spring Framework已經從HashMap繼承,並放置了一個方法 繼承形式HashMap。

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/ui/ModelMap.html

+0

這是不正確的,如果你檢查,你會看到,這兩種方法都只是的addAttribute檢查空相同的實行。 – Aladdin

相關問題